UNIT-II Data Representation
UNIT-II Data Representation
Integer Representation
Computers use a fixed number of bits to represent an integer. The commonly-used bit-lengths
for integers are 8-bit, 16-bit, 32-bit or 64-bit. Besides bit-lengths, there are two representation
schemes for integers:
1. Unsigned Integers:
These are binary numbers that are always assumed to be positive.
Here all available bits of the number are used to represent the magnitude of the
number. No bits are used to indicate its sign; hence they are called unsigned numbers.
E.g.: Roll Numbers, Memory addresses etc.
Therefore, all positive numbers including zero can be treated as unsigned numbers.
2. Signed Integers:
These are binary numbers that can be either positive or negative.
The MSB of the number indicates whether it is positive or negative.
If MSB is 0 then the number is Positive.
If MSB is 1 then the number is Negative.
Negative numbers are always stored in their 2's Complement form.
1. Two's complement gives a unique representation for zero. Any other system gives a
separate representation for 0 and for -0. This is absurd.
In two's complement system, - (x) is stored as two's complement of (x). Applying the
same rule for 0, - (0) should be stored as two's complement of 0. O is stored as 000. So , -
(0) should be stored as two's complement of 0 which again is 000. Hence two's complement
gives a unique representation for 0.
4 BIT INTEGER
4
2 = 16 , 𝑡ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 16 𝑐𝑜𝑚𝑏𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑠
Unsigned signed
0 .........15 -8........-1 ,0,1.......7
5 BIT INTEGER
25 = 32 , 𝑡ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 32 𝑐𝑜𝑚𝑏𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑠
Unsigned signed
0 .........31 -16........-1 ,0,1.......15
8 BIT INTEGER
28 = 256 , 𝑡ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 256 𝑐𝑜𝑚𝑏𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑠
Unsigned signed
0 .........255 -128........-1 ,0,1.......127
16 BIT INTEGER
216 = 65536 , 𝑡ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 65536 𝑐𝑜𝑚𝑏𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑠
Unsigned signed
0 .........65535 -32768........-1 ,0,1.......32767