Lab Handout-2
Lab Handout-2
Lab Handout 2
Objectives
• Differentiate between Decimal, Binary & Hexadecimal numbers.
• Conversion between Decimal, Binary & Hexadecimal numbers.
Base 10 (decimal)
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)
Binary to decimal
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,
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
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,
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
Page 3
Computer Organization
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
Once discerned, notice that the above process is essentially performing this calculation:
• 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
160 1
161 = 16 16
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
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
Page 9