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