CSET‐201: Computer Organization
Lab Handout 2
Data representation & conversion
Objectives
• Differentiate between Decimal, Binary & Hexadecimal numbers.
• Conversion between Decimal, Binary & Hexadecimal numbers.
Base 10 (decimal)
We use a sequence of digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 to represents numbers in our daily
work, for example 1996. The number 1996 means one thousand plus nine hundred plus
ninety and plus six, as you know. Written formally
1996 = 1 * 1000 + 9 * 100 + 9 * 10 + 6 * 1
= 1 * 103 + 9 * 102 + 9 * 101 + 6 * 100
Each earlier digit contributes to the value ten times larger than the next digit. The
number 10 is said to be the base or radix of the representation. Such system is called a
positional notation system.
Base 2 (binary)
It is not necessary that each digit contributes to a power of 10 according to its position in
the number. We can use power of 2 instead, and with only two (binary) digits 0 and 1. So in
binary 102 is the value 210. (This lab will use convention n2 to indicate binary number and
n10 for decimal number). Thus
10112 = 1 * 23 + 0 * 22 + 1 * 21 + 1 * 20
= 8 + 0 + 2 + 1
= 1110
It's good to know the first few values of powers of two for binary to decimal conversion:
20 = 1; 26 = 64;
21 = 2; 27 = 128;
22 = 4; 28 = 256;
23 = 8; 29 = 512;
24 = 16; 210 = 1024;
25 = 32; 211 = 2048.
Page 1
Computer Organization
Base 16 (hexadecimal)
Hexadecimal numbers need digits from 0 to 15, they are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B,
C, D, E, F where A for 10, B for 11, and so on. In hexadecimal, each digit represents a
power of 16. So
10FA16 = 1 * 163 + 0 * 162 + 15 * 161 + 10 * 160
= 1 * 4096 + 0 * 256 + 15 * 16 + 10 * 1
= 4096 + 0 + 240 + 10
= 434610
Conversion between Representations
Binary to decimal
Here is one more example
10010011 = 27 + 0 + 0 + 24 + 0 + 0 + 21 + 20
= 128 + 16 + 2 + 1
= 147
Whenever there is a 1, there is a contribution of the form 2i, i is the location of the digits
counting from right to left, starting from 0.
Decimal to binary
Here is the rule,
147/2 = 73 + 1/2 -> 1 (right most, least significant digit)
73/2 = 36 + 1/2 -> 1
36/2 = 18 + 0/2 -> 0
18/2 = 9 + 0/2 -> 0
9/2 = 4 + 1/2 -> 1
4/2 = 2 + 0/2 -> 0
2/2 = 1 + 0/2 -> 0
1/2 = 0 + 1/2 -> 1 (left, most significant digit)
So the binary representation is (reading backwards)
10010011
In summary, the number is divided by 2, and the results are the quotient and reminder;
the digit in the reminder is the binary digit; the quotient is divided by 2 again, until the
quotient become zero. The binary digits from least significant to most significant are found
in the reminders.
Page 2
Computer Organization
Binary to hexadecimal, hexadecimal to binary
Due to the fact that 24 = 16, the conversion is very easy. Simply divide the binary digits
into group of four (starting from the least significant bit) and use the correspondence
between decimal number from 0 to 15, hexadecimal number from 0 to F, and binary four
digits number 0000 to 1111,
decimal hex binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
For example, binary number representation <-> hexadecimal representation:
0001 0000 1111 1010 <-> 10FA
Page 3
Computer Organization
Hexadecimal to decimal conversion
Steps:
1. Get the last digit of the hex number, call this digit the current Digit.
2. Make a variable, let's call it power. Set the value to 0.
3. Multiply the current digit with (16power), store the result.
4. Increment power by 1.
5. Set the current Digit to the previous digit of the hex number.
6. Repeat from step 3 until all digits have been multiplied.
7. Sum the result of step 3 to get the answer number.
Page 4
Computer Organization
Example 1
Convert the number 1128 HEXADECIMAL to DECIMAL
MULTIPLICATION RESULT NOTES
Start from the last digit of the number. In
this case, the number is 1128. The last
8 x (160) 8
digit of that number is 8. Note that the
power of 0 of any number is always 1
Process the previous, which is 2. Multiply
2 x (161) 32 that number with an increasing power of
16.
Process the previous digit, which is 1, note
1 x (162) 256
that 162 means 16 x 16
Process the previous digit, which is 1, note
1 x (163) 4096
that 163 means 16 x 16 x 16
Here, we stop because there's no more digit
to process
This number comes from the sum of the
ANSWER 4392 RESULTS
(8+32+256+4096)=4392
Once discerned, notice that the above process is essentially performing this calculation:
1x(163) + 1x(162) + 2x(161) + 8x(160)
When doing this by hand, it is easier to start backward is because:
• Counting the number of digits takes extra time, and you might count wrongly.
• If you don't remember what a particular value of a power-of-16 is, it's easier to calculate it from the
previous power value. For instance, if you don't remember what the value of 163 is, then just multiply
the value of 162 (which you'll likely already have if you started backward) with 16.
Page 5
Computer Organization
Example 2
Convert the number 589 HEXADECIMAL to DECIMAL
MULTIPLICATION RESULT
9 x (160) 9
8 x (161) 128
5 x (162) 1280
ANSWER 1417
If you want to be a speed counter, it's beneficial to memorize the values of the smaller power of 16s, such as in
this table
POWER OF 16s RESULT
160 1
161 = 16 16
162 = 16x16 256
163 = 16x16x16 4096
164 = 16x16x16x16 65536
Page 6
Computer Organization
Problem
Convert the number 1531 HEXADECIMAL to DECIMAL
(This time, let's use the table of the power-of-16s above.)
MULTIPLICATION RESULT
ANSWER
Example 3
Convert the number FA8 HEXADECIMAL to DECIMAL
MULTIPLICATION RESULT
8x1 8
A x 16 (remember that hex A=decimal 10) 160
F x 256 (remember that hex F=decimal 15) 3840
ANSWER 4008
Page 7
Computer Organization
Problem
Convert the number 8F HEXADECIMAL to DECIMAL
DIVISION RESULT
ANSWER
Example 6
Convert the number A0 HEXADECIMAL to DECIMAL
DIVISION RESULT
ANSWER
Example 7
Convert the number 12 HEXADECIMAL to DECIMAL
DIVISION RESULT
ANSWER
Page 8
Computer Organization
Problems
1. Convert following decimal numbers into binary.
a. 183
b. 200
c. 580
2. Convert the following binary number to decimal.
a. 01001101.
b. 00111001.
c. 10101010
3. Convert the following Hexadecimal numbers to binary and decimal.
a. 3A44
b. FFB2
c. CCE8
Page 9