Computer Architecture
Data Representation
Number SystemNumber of digits used in a number system is called its base or radix. We can categorize number system as below:
- Binary number system
- Octal Number System
- Decimal Number System
- Hexadecimal Number system
Representation of Decimal numbers
We can normally represent decimal numbers in one of following two ways
- By converting into binary
- By using BCD codes
By converting into binary
Advantage
Arithmetic and logical calculation becomes easy. Negative numbers can be represented easily.
Disadvantage
At the time of input conversion from decimal to binary is needed and at the time of output conversion from binary to decimal is needed.
Therefore this approach is useful in the systems where there is much calculation than input/output.
By using BCD codes
Disadvantage
Arithmetic and logical calculation becomes difficult to do. Representation of negative numbers is tricky.
Advantage
At the time of input conversion from decimal to binary and at the time of output conversion from binary to decimal is not needed.
Therefore this approach is useful in the systems where there is much input/output than arithmetic and logical calculation.
Complements
(R-1)'s Complement
(R-1)'s complement of a number N is defined as (rn -1) –N
Where N is the given number
r is the base of number system
n is the number of digits in the given numberv To get the (R-1)'s complement fast, subtract each digit of a number from (R-1)
Example
- 9's complement of 83510 is 16410
- 1's complement of 10102 is 01012(bit by bit complement operation)
R's Complement
R's complement of a number N is defined as rn–N
Where N is the given number
r is the base of number system
n is the number of digits in the given number
To get the R's complement fast, add 1 to the low-order digit of its (R-1)'s complement
- 10's complement of 83510 is 16410 + 1 = 16510
- 2's complement of 10102 is 01012 + 1 = 01102
Representation of Negative numbers
There is only one way of representing positive numbers in computer but we can represent negative numbers in any one of following three ways:
- Signed magnitude representation
- Signed 1’s complement representation
- Signed 2’s complement representation
Signed magnitude representation
Complement only the sign bit
e.g.
+9 ==> 0 001001
-9 ==> 1 001001
Signed 1’s complement representation
Complement all the bits including sign bit
e.g.
+9 ==> 0 001001
-9 ==> 1 110110
Signed 2’s complement representation
Take the 2's complement of the number, including its sign bit.
e.g.
+9 ==> 0 001001
-9 ==> 1 110111