Professional Documents
Culture Documents
Number System - Conversion
Number System - Conversion
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 10000 20 10
0.11001
0.8110 => 0.81 x 2 = 1.62 12
0.62 x 2 = 1.24
0.24 x 2 = 0.48 0.48
x 2 = 0.96
0.96 x 2 = 1.92
0.92 x 2 = 1.84
= 0.1100112 (approximately)
Converting a binary number into decimal
(binary decimal)
A. Multiply each bit in the binary
number with the weight (or position)
B. Add up all the results of the
multiplication performed
C. The desired decimal number is the
total of the multiplication results
performed
Example: Binary Decimal
a)1110012 (6 bits)
Þ(1x25) + (1x24) + (1x23) + (0x22) +
(0x21) + (1x20)
= 32 + 16 + 8 + 0 + 0 + 1
= 5710
b)000110102 (8 bits)
= 24 + 23 +21
= 16 + 8 + 2
= 2610
Binary and Octal
Theorem
If base R1 is the integer power of
other base, R2, i.e.
R1 = R2d
e.g., 8 = 23
Every group of d digits in R2
(e.g., 3 digits)is equivalent to
1 digit in the R1 base
0 5 7 3 6 4
= 578 = 3648
Binary and Hexadecimal
• The same method employed in binary-octal
conversion is used once again.
• Assume that:
R1 = 16 (hexadecimal)
R2 = 2 (binary)
• From the theorem: 16 = 24
Hence, 4 digits in a binary number is
equivalent to 1 digit in the hexadecimal
number system (and otherwise)
• The following is the binary-hexadecimal
conversion table
Binary Hexadecimal Example:
0000 0
0001 1 1.Convert the following binary
0010 2 numbers into hexadecimal
0011 3 numbers:
0100 4
0101 5 (a) 001011112
0110 6 Refer to the binary-
0111 7 hexadecimal conversion table
1000 8 above
1001 9
1010 A 0010 11112 = 2F16
1011 B
1100 C 2 F
1101 D
1110 E
1111 F
Example: Octal Hexadecimal
Convert the following octal numbers
into hexadecimal numbers (16 bits)
(a) 658 (b) 1238
Refer to the binary-octal conversion table Refer to the binary-octal conversion table
68 58 18 28 38
110 101 001 010 011
0000 0000 0011 01012 0000 0000 0101 00112
0 0 3 5 0 0 5 3
= 3516 = 5316
octal binary hexadecimal
Example: Hexadecimal Binary
1 2 B16 A B C D16
= 0001001010112 = 10101011110111102
Exercise 1
• Binary decimal
– 001100
– 11100.011
• Decimal binary
– 145
– 34.75
• Octal hexadecimal
– 56558
Solution 1
• Binary decimal
– 001100 = 12 0x2 +0x2 +1x2 +1x2 +0x2 +0x2
5 4 3 2 1 0
= 8 +4 = 12
– 11100.011 = 28.375
• Decimal binary
– 145 = 10010001 145/2 = 72 (reminder 1); 72/2=36(r=0); 36/2=18(r=0);
– 34.75 = 100010.11 18/2=9(r=0); 9/2=4(r=1); 4/2=2(r=0); 2/2=1(r=0); ½=0(r=1)
• Octal hexadecimal
octal binary decimal hexadecimal
– 56558 = BAD Octal binary
101:110:101:101
Binary hexadecimal
1011:1010:1101
B A D
Solution 1
• Octal hexadecimal
octal binary hexadecimal
– 56558 = BAD
Exercise 2
• Binary decimal
– 110011.10011 51.59375
• Decimal binary
– 25.25 11001.01
• Octal hexadecimal
– 128 B
Signed Integer Representation
• Signed integers are usually used
by programmers
• Unsigned integers are used for
addressing purposes in the
computer (especially for
assembly language programmers)
• Three representations of signed
integers:
1. Sign-and-Magnitude
2. Ones Complement
3. Twos Complement
Sign-and-Magnitude
(+7) = 0001112
(+10)10 = 0010102
So,
(-10)10 = 1101012
Twos complement
111110102 + 12 = 111110112
–5 in twos complement is 111110112
Exercise:
(-10) 10
= 1101012 + 12
= 1101102
So, twos compliment
Exercise:
Obtain representation for the following
numbers
Decimal Sign-magnitude Twos complement
+7
+6
4 bits
-4
-6
-7
+18
8 bits
-18
-13
Solution:
Obtain representation for the following
numbers
Decimal Sign-magnitude Twos complement
+7 0111 0111
+6 0110 0110
-4 1100 1100
-6 1110 1010
-7 1111 1001
+18 00010010 00010010
-18 10010010 11101110
-13 10001101 11110011
Character Representation
• For character data type, its
representation uses codes
such as the ASCII, IRA or
EBCDIC.
1. Addition ( + ) 010111
0 + 0 = 0 011110 +
0 + 1 = 1
110101
1 + 0 = 1
1 + 1 = 10
1 + 1 + 1 = (1 + 1) + 1 = 10 + 1 = 112
Example:
i. 0101112 + 0111102 = 1101012
ii. 1000112 + 0111002 = 1111112
2. Multiplication ( x )
0 x 0 = 0
0 x 1 = 0
1 x 0 = 0
1 x 1 = 1
3. Subtraction ( – )
0 – 0 = 0
0 – 1 = 1 (borrow 1)
1 – 0 = 1
1 – 1 = 0
4. Division ( / )
0 / 1 = 0
1 / 1 = 1
Example:
i. 0101112 - 0011102 = 0010012
ii. 1000112 - 0111002 = 0001112
Exercise:
i. 1000100 – 010010 v. 110111 + 001101
ii. 1010100 + 1100 vi. 111000 + 1100110
iii. 110100 – 1001 vii. 110100 x 10
iv. 11001 x 11 viii. 11001 - 1110
Arithmetic Operations for Ones Complement,
Twos Complement, sign-and-magnitude and
floating point number
Z = X + Y
There are a few possibilities:
i. If both numbers, X and Y are
positive
o Just perform the addition operation
Example:
510 + 310 = 0001012 + 0000112
= 0010002
= 810
ii. If both numbers are negative
o Add |X| and |Y| and set the sign bit = 1
to the result, Z
Example: –310 – 410 = (–3) + (–4)
= 1000112 + 1001002
Only add the magnitude, i.e.:
000112 + 001002 = 001112
Set the sign bit of the result
(Z) to 1 (–ve)
= 1001112
= –710
iii. If signs of both number differ
o There will be 2 cases:
11110111
+ 1
111110002 = –710
the answer
2. | +ve Number| > |–ve Number|
• This case will also cause an
overflow
Example: (–2) + 4 = (–2) + (+4)
Solution:
• Change both of the numbers above
into one’s complement
representation
–2 = 111111012 +4 = 000001002
• Add both of the numbers
(–210) => 11111101 (8 bit)
+ (+410) => 00000100 (8 bit)
+210 100000001 (9 bit)
There is an EAC
•Add the EAC to the rightmost bit
00000001
+ 1
000000102 = +210
the answer
Note:
For cases other than 1 & 2 above, overflow does not occur
and there will be no EAC and the need to perform addition to
the rightmost bit does not arise
Twos Complement