"Csapp reading note two" on the daily life of integers and floating-point numbers

Source: Internet
Author: User
Tags binary to decimal

Part I:integer

There is types of integer:unsigned integer (only positive) & signed integer (positive,negative and 0)
So what does a computer storage an integer?

1.Regarding unsigned integer:

CPU use binary to represent unsigned integer directly.
eg:2333---1001 0001 1101
Notice that large integer needs wide-ranging datatype.
eg: unsigned int datatype can storage integer ranging from 0 to 4294967295
unsigned long long : 0 to 18,446,744,073,709,551,615
(for 32bit CPUs only)

2.Regarding signed integer:

An essential bit must is allocated in order to record whether it ' s positive or negative.
Many modern computer use , s-compelement encodings to represent signed integer.
Assume we use 4 bits to save a integer (bit 0~3) with each bit have a unique weight
      bit: & nbsp     X        x         X        x
weight:-(2^3) (2^2) (2^1) (2^0)
That seems just like unsigned integer, aha~.
But it's a difference:the weight of the highest bit is a negative value, which'll also determine the sign.
Here is 3 examples:
1.0101     (2^2) + (2^1)                = 5 2. 1011    -(2^3) + (2^1) + (2^0)    =-5
3.0000     = 0

In computer, the binary code might is the same, but the value might is totally different.
That depends in different decoding standard.
eg
Unsigned int:0 ...    127 128 ... 255
Signed int:0 ... 127-128 ...-1
binary:00000000 ... 01111111 10000000 ... 11111111
Hexadecimal:00 ...    7F 80 ... Ff

Ps:
There is many mathematcial practices in the period on Csapp.
Just like converting from binary to decimal, as well as decode a binary for unsigned or signed.
But in my opinion they aren ' t that useful:P

"Csapp reading note two" on the daily life of integers and floating-point numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.