Chapter 4-Data Representation in Computers
Chapter 4-Data Representation in Computers
Chapter 4
Data Representation in computers
___________________________________________
__________
- computers are built from components that have two values; on/off
- the binary number system, which has only two digits 0 and 1 is used to express
the two states
- internal arithmetic operations of a digital computer are actually performed in
binary number system
Page 1 of 8
Chapter 4: Data Representation in computers
- place value
10n… 101 100. 10-110-2... 10-m
An… a1 a0 . a-1 a-2 … a-m
- the general form is: X= an * 10n + … + a1*101+a0*100 + a-1 * 10-1 + … + a-m * 10-m
n
= ∑ ai * 10i
i= -m
e.g.
- the decimal number 852.37 is equal to 8*102 +5 *101+ 2*100 +3*10-1 + 7*10-2
- Likewise, substituting any base in place of 10 will give the general form of a
number to that radix.
- In computer science 4 bases are of concerns: base 2, base 8, base 10 and base 16.
And the number systems in these bases are binary, octal, decimal and
hexadecimal respectively.
- Summary
Base Number System Possible Symbols(digits)
2 Binary 0 and 1
8 Octal 0-7
10 Decimal 0-9
16 Hexadecimal 0-9 and A-F
- Base n number has n possible digits and the digits are 0 to n-1
III. Conversion from One Base to Another
Step 1. Convert a given number to decimal number
Step 2. Convert the obtained no to the desired base
Page 2 of 8
Chapter 4: Data Representation in computers
Step 3. The number in the desired base consists of the integer obtained in step 1
followed by a base point and then followed by the fractional number part obtained in
step 2
Step 1 Explained:
To convert an integer to a base B integer number
1. Divide the given integer by the base B
2. Repeat step 1 until a 0 quotient is obtained, using at each stage the quotient from
the previous stages as dividend
The successive remainders (starting from the least significant end) are the successive
digits of the number in base B
e.g convert
a) 67 to binary
b) 256 to binary
c) 256 to hexadecimal
Step 2 Explained:
To convert a decimal fraction to a fraction in base B
1. Multiply the given decimal fraction in base B
2. Repeat step 1 using the multiplicand at each step the remaining fractional part
from the previous step until a fractional part is identically 0, or until as many
digits as desired have been generated. The successive integral parts are the
successive digits of the number in base B starting from the most significant
end.
E.g convert
a) (.65)10 to binary
b) (.44)10 to quinary
c) (.32)10 to hexadecimal
Solution
.65 *2 = 1.3
.30 * 2 = .60
.60 * 2 = 1.20
.20 * 2 = .40
.40 * 2 = .80
.80 * 2 = 1.60
.60 * 2 = 1.20
.
.
. ____
Ans: (101001)
E.g Convert a) (256.65)10 to binary
b) (256.32)10 to hexadecimal
c) (10011.101)2 to quinary
Page 3 of 8
Chapter 4: Data Representation in computers
- group the binary digits in triplets starting at the binary point and convert each of
these to its octal equivalent
o you can add 0’s on the right and left, if necessary, to form a complete
triplet
o e.g. a) (110 011.010 110)2 = (63.26)8
Octal-to-Binary
- writing the binary triplets for each octal digits
- e.g. a) (63.26)8 = (110 011.010 110)2
b) (65.61)8 = (110 101.110 001)2
Binary-to-Hexadecimal
- group the binary digits in quadriplets starting at the binary point and convert each
of these to its hexadecimal equivalent
o you can add 0’s on the right or left, if necessary, to form a complete
quadriplets
e.g. (11 0011.0101 10)2 = (33.58)16
(11 1100 1011.1001 1)2 = (3CB.98)16
Hexadecimal-to-Binary
- write the binary quadruplet for each hexadecimal digits
e.g.
a) (33.58)16 = (0011 0011.0101 1000)2
b) (4E93)16 = (0100 1110 1001 0011)2
Octal-to-Hexadecimal
- octal-to-binary-to-hexadecimal
- convert (65)16 to octal
Hexadecimal-to-Octal
- hexadecimal-to-binary-to-octal
- e.g. convert (33)16 to octal
Remark: when you convert signed number, ignore the sign during conversion. After
the number in the desired base has been obtained, affix the sign of the original
number to the desired number
E.g. convert (-125)10 to base 5
Notice: before you start converting a number to a specified base, check whether the
given number is legal one
e.g. (230)2 is illegal and same is true for (98)8
BCD codes
- represent a numerical value
- is a 4 bit code
- in BCD code each decimal digit is coded into groups of 4 bits
- to convert a decimal number to BCD forms, simply encode each decimal digit
into groups of 4 bits
e.g. 129 = 0001 0010 1001
Exercise
1. convert 192 to base 2
2. convert 192 to base 8
3. convert 192 to base 16
Page 4 of 8
Chapter 4: Data Representation in computers
Page 5 of 8
Chapter 4: Data Representation in computers
b) 6 00110 00110
-12 +10011 +10100
-6 11001 11010
Page 6 of 8
Chapter 4: Data Representation in computers
N.B if the sign bits of A and B are the same but the sign of the result is different,
arithmetic overflow occurs. In case of “c” arithmetic overflow occurred.
Floating Point Numbers
- The two basic methods of binary number representation in computers are integer
representation and floating point representation.
- Floating point numbers are numbers in the normalized form: A * bx, where;
A is mantissa
B is base (radix)
X is exponent
E.g. The decimal number 46.5 = 0.465*102
Mantissa=0.465
Base=10
Exponent=2
The binary number 1101.11 = 0.0110111*24
Mantissa = 0.0110111
Base =2
Exponent=4
- floating point representation
Sign Exponent Mantissa
- exponent is represented by a biased exponent which is expressed by:
True exponent + excess 2n-1, n is the number of bits representing the
exponent
- true exponent + excess 2n-1 is called characteristics
E.g1.convert 9.5 to normalized binary floating point form using 7 bit
exponent and 16 bit mantissa
Solution
9= (1001)2 = 0.1001 * 24
0.5 = (0.1)2 = 0.1 *20
Hence, normalized exponential form of 9.5 is 0.10011 * 24
Characteristic = true exponent + excess 2n-1
= 4 + 27-1
=68= (1000100)2
9.5 is represented as:
0 1000100 10011000…0
----7 bits-- ---16 bits------
E.g2. convert -18.375 to normalized binary floating point form using 7 bit
exponent and 16 bit mantissa.
Solution
18 = (10010)2 = 0.10010 * 25
0.375 = (0.011)2 = 0.011 * 20
Page 7 of 8
Chapter 4: Data Representation in computers
=5 + 64 = 69 = (1000101)2
Thus, the representation of -18.375 is:
1 1000101 10010011000…0
---7 bits------- ----------16 bits----------
- If the mantissa has fewer digits than the required bit positions, zeros are added to
the end of the mantissa
- If the characteristic has fewer digits than the required bit positions, zeros are
added to the beginning of the characteristic
- Exercise
1. Perform the following operations in binary
a. 1101.01 + 11.11
b. 1101.01 * 11.11
2. Perform the following subtraction using twos complement in 6 bits
a. 111100 – 111011
b. 1101.010 – 11.1101
3. Repeat problem 2 using 1’s complement
4. convert 4.375 to normalized binary floating point form (7 bit exponent,
16 bit mantissa)
5. convert -4.350 to normalized binary floating point form (8 bit
exponent and 27 bit mantissa)
Page 8 of 8