Unit 1 Part C
Unit 1 Part C
Representation
and Computer
Arithmetic
By Dr. Charu Goyal
Data Representation
Method of storing and manipulating data in
computer system.
This includes numbers, characters, and
instructions.
There are 3 ways of representing the data:
Signed Number Representation
Fixed-Point Representation
Floating-Point Representation
Signed Number
Representation
Signed Number Representation
Signed numbers can be represented in three primary ways:
1.Sign-Magnitude Representation: The leftmost bit (MSB) is the sign bit (0 for
positive, 1 for negative), while the remaining bits represent the magnitude.
•Example: 5 → 00000101, -5 → 10000101
•The range of signed integer representation of an n-bit number is given as –
(2^{n-1}-1) to (2)^{n-1}-1.
Let n = 4
Range:
–(2^{4-1}-1) to 2^{4-1}-1
= -(2^{3}-1) to 2^{3}-1
= -(7) to+7
For 4 bit representation, minimum value=-7 and maximum value=+7
Drawbacks:
1. For 0, there are two representations: -0 and +0 which should not
be the case as 0 is neither –ve nor +ve.
2. Out of 2^n bits for representation, we are able to utilize
only 2^{n-1} bits.
3. Numbers are not in cyclic order i.e. After the largest number (in
this, for example, +7) the next number is not the least number (in
this, for example, +0).
4. For negative numbers signed extension does not work.
5. For +ve representation, if 4 bits are extended to 5 bits there is a
need to just append 0 in MSB.
6. But if the same is done in –ve representation we won’t get the
same number. i.e. 10101 ≠ 11101.
Signed Number
Representation
2.One’s Complement Representation: Negative numbers are obtained by inverting all bits
of the positive number.
•Example: 5 → 00000101, -5 → 11111010
For –ve numbers, we can follow any one of the two approaches:
Write the +ve number in binary and take 1’s complement of it.
1. For 0, there are two representations: -0 and +0 which should not be the case as
0 is neither –ve nor +ve.
2. Out of 2^n bits for representation, we are able to utilize only 2^{n-1} bits.
Example:
(-5) in 4-bit representation
2^4-5=11 -→1011(unsigned)
Example:
(-5) in 2’s complement
(+5) = 0101
1’s complement of (+5) = 1010
Add 1 in 1010: 1010+1 = 1011
Therefore (-5) = 1011