Data Representation
Â
Data in computer is represent in binary form i.e 0 and 1 .
To know data representation in computer we must know following number system:
Â
a)Â Decimal number system: 0,1,2,3,4,5,6,7,8,9 Base=10
Â
b)Â Binary number system: 0,1 Base=2
Â
c)Â Â Octal number System: 0,1,2,3,4,5,6,7 Base=8
Â
d)Â Hexa Decimal System: 0,1,2,3,4,5,6,7,8,9,A(10),B(11),C(12),D(13),E(14),F(15); Base =16
Â
A repeated division and remainder algorithm can convert decimal to binary, octal, or hexadecimal.
Â
1.Â Divide the decimal number by the desired target radix (2, 8, or 16).
Â
2.Â Append the remainder as the next most significant digit.
Â
3.Â Repeat until the decimal number has reached zero.
Â
Decimal to Binary
Here is an example of using repeated division to convert 1792 decimal to binary:Â
Decimal Number 
Â Â Operation 
Â Â Quotient 
Â Â Remainder 
Â Â Binary Result 
1792 
Ã· 2 = 
896 
0 
0 
896 
Ã· 2 = 
448 
0 
00 
448 
Ã· 2 = 
224 
0 
000 
224 
Ã· 2 = 
112 
0 
0000 
112 
Ã· 2 = 
56 
0 
00000 
56 
Ã· 2 = 
28 
0 
000000 
28 
Ã· 2 = 
14 
0 
0000000 
14 
Ã· 2 = 
7 
0 
00000000 
7 
Ã· 2 = 
3 
1 
100000000 
3 
Ã· 2 = 
1 
1 
1100000000 
1 
Ã· 2 = 
0 
1 
11100000000 
0 
done. 
Â
Decimal to Octal
Here is an example of using repeated division to convert 1792 decimal to octal:
Â
Decimal Number 
Â Â Operation 
Â Â Quotient 
Â Â Remainder 
Â Â Octal Result 
1792 
Ã· 8 = 
224 
0 
0 
224 
Ã· 8 = 
28 
0 
00 
28 
Ã· 8 = 
3 
4 
400 
3 
Ã· 8 = 
0 
3 
3400 
0 
done. 
Â
Â
Decimal to Hexadecimal
Here is an example of using repeated division to convert 1792 decimal to hexadecimal:
Â
Decimal Number 
Â Â Operation 
Â Â Quotient 
Â Â Remainder 
Â Â Hexadecimal Result 
1792 
Ã· 16 = 
112 
0 
0 
112 
Ã· 16 = 
7 
0 
00 
7 
Ã· 16 = 
0 
7 
700 
0 
done. 
The only addition to the algorithm when converting from decimal to hexadecimal is that a table must be used to obtain the hexadecimal digit if the remainder is greater than decimal 9.
Â
Decimal: 
0 
1 
2 
3 
4 
5 
6 
7 
Hexadecimal: 
0 
1 
2 
3 
4 
5 
6 
7 
Decimal: 
8 
9 
10 
11 
12 
13 
14 
15 
Hexadecimal: 
8 
9 
A 
B 
C 
D 
E 
F 
Â
The addition of letters can make for funny hexadecimal values. For example, 48879 decimal converted to hex is:
Â
Decimal Number 
Â Â Operation 
Â Â Quotient 
Â Â Remainder 
Â Â Hexadecimal Result 
48879 
Ã· 16 = 
3054 
15 
F 
3054 
Ã· 16 = 
190 
14 
EF 
190 
Ã· 16 = 
11 
14 
EEF 
11 
Ã· 16 = 
0 
11 
BEEF 
0 
done. 
Â
Other fun hexadecimal numbers include: AD, BE, FAD, FADE, ADD, BED, BEE, BEAD, DEAF, FEE, ODD, BOD, DEAD, DEED, BABE, CAFE, C0FFEE, FED, FEED, FACE, BAD, F00D, and my initials DAC.
Â
Octal To Binary
Converting from octal to binary is as easy as converting from binary to octal. Simply look up each octal digit to obtain the equivalent group of three binary digits.
Â
Octal: Â 
0 Â 
1 Â 
2 Â 
3 Â 
4 Â 
5 Â 
6 Â 
7 Â 

Binary: Â 
000  001  010  011  100  101  110  11 Â 
Octal:  3  4  5  Â 
Binary:  011  100  101  =011100101 binary 
Â
Octal to Hexadecimal
When converting from octal to hexadecimal, it is often easier to first convert the octal number into binary and then from binary into hexadecimal. For example, to convert 345 octal into hex:
(from the previous example)
Octal = 
3 
4 
5 

Binary = 
011 
100 
101 
= 011100101 binary 
Drop any leading zeros or pad with leading zeros to get groups of four binary digits (bits):
Binary 011100101 = 1110 0101
Then, look up the groups in a table to convert to hexadecimal digits.
Binary: 
0000 
0001 
0010 
0011 
0100 
0101 
0110 
0111 
Hexadecimal: 
0 
1 
2 
3 
4 
5 
6 
7 
Binary: 
1000 
1001 
1010 
1011 
1100 
1101 
1110 
1111 
Hexadecimal: 
8 
9 
A 
B 
C 
D 
E 
F 
Binary = 
1110 
0101 

Hexadecimal = 
E 
5 
= E5 hex 
Therefore, through a twostep conversion process, octal 345 equals binary 011100101 equals hexadecimal E5.
Octal to Decimal
Converting octal to decimal can be done with repeated division.
Â
1.Â Start the decimal result at 0.
Â
2.Â Remove the most significant octal digit (leftmost) and add it to the result.
Â
3.Â If all octal digits have been removed, youâ€™re done. Stop.
Â
4.Â Otherwise, multiply the result by 8.
Â
5.Â Go to step 2.
Â
Octal Digits 
Â Â Operation 
Â Â Decimal Result 
Â Â Operation 
Â Â Decimal Result 
345 
+3 
3 
Ã— 8 
24 
45 
+4 
28 
Ã— 8 
224 
5 
+5 
229 
done. 
Â
The conversion can also be performed in the conventional mathematical way, by showing each digit place as an increasing power of 8.
345 octal = (3 * 8^{2}) + (4 * 8^{1}) + (5 * 8^{0}) = (3 * 64) + (4 * 8) + (5 * 1) = 229 decimal
Converting from hexadecimal is next...
Converting from hexadecimal to binary is as easy as converting from binary to hexadecimal. Simply look up each hexadecimal digit to obtain the equivalent group of four binary digits.
Â
Hexadecimal: 
0 
1 
2 
3 
4 
5 
6 
7 
Binary: 
0000 
0001 
0010 
0011 
0100 
0101 
0110 
0111 
Hexadecimal: 
8 
9 
A 
B 
C 
D 
E 
F 
Binary: 
1000 
1001 
1010 
1011 
1100 
1101 
1110 
1111 
Â
Hexadecimal = 
A 
2 
D 
E 

Binary = 
1010 
0010 
1101 
1110 
= 1010001011011110 binary 
Hexadecimal to Octal
When converting from hexadecimal to octal, it is often easier to first convert the hexadecimal number into binary and then from binary into octal. For example, to convert A2DE hex into octal:
Â
(from the previous example)
Â
Hexadecimal = 
A 
2 
D 
E 

Binary = 
1010 
0010 
1101 
1110 
= 1010001011011110 binary 
Add leading zeros or remove leading zeros to group into sets of three binary digits.
Binary: 1010001011011110 = 001 010 001 011 011 110
Then, look up each group in a table:
Â
Binary: 
000 
001 
010 
011 
100 
101 
110 
111 
Octal: 
0 
1 
2 
3 
4 
5 
6 
7 
Â
Binary = 
001 
010 
001 
011 
011 
110 

Octal = 
1 
2 
1 
3 
3 
6 
= 121336 octal 
Therefore, through a twostep conversion process, hexadecimal A2DE equals binary 1010001011011110 equals octal 121336.
Hexadecimal to Decimal
Converting hexadecimal to decimal can be performed in the conventional mathematical way, by showing each digit place as an increasing power of 16. Of course, hexadecimal letter values need to be converted to decimal values before performing the math.
Â
Â
Hexadecimal: 
0 
1 
2 
3 
4 
5 
6 
7 
Decimal: 
0 
1 
2 
3 
4 
5 
6 
7 
Hexadecimal: 
8 
9 
A 
B 
C 
D 
E 
F 
Decimal: 
8 
9 
10 
11 
12 
13 
14 
15 
A2DEhexadecimal:
= ((A) * 16^{3}) + (2 * 16^{2}) + ((D) * 16^{1}) + ((E) * 16^{0})
= (10 * 16^{3}) + (2 * 16^{2}) + (13 * 16^{1}) + (14 * 16^{0})
= (10 * 4096) + (2 * 256) + (13 * 16) + (14 * 1)
= 40960 + 512 + 208 + 14
= 41694 decimal