Week 1 Number System
Week 1 Number System
Number system
1
Number System
Where:
N: an integer with n+1 digits
r: base
ai ∈ {0, 1, 2, … , r-1}
Examples:
a) N = 278
r = 10 (base 10) => decimal numbers
symbol: 0, 1, 2, 3, 4, 5, 6, 7,
8, 9 (10 different symbols)
N = 278 => n = 2;
a2 = 2; a1 = 7; a0 = 8
c) N = 2638
r = 8 (base-8) => Octal numbers
symbol : 0, 1, 2, 3, 4, 5, 6, 7,
(8 different symbols)
N = 2638 => n = 2; a2 = 2; a1 = 6; a0 = 3
2638 = (2 x 82) + (6 x 81) + (3 x 80)
d) N = 26316
r = 16 (base-16) => Hexadecimal numbers
symbol : 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, A, B, C, D, E, F
(16 different symbols)
N = 26316 => n = 2;
a2 = 2; a1 = 6; a0 = 3
5310 =>
53 / 2 = 26 remainder 1
26 / 2 = 13 remainder 0
13 / 2 = 6 remainder 1
6 / 2 = 3 remainder 0
3 / 2 = 1 remainder 1
1 / 2 = 0 remainder 1
= 1101012 (6 bits)
= 001101012 (8 bits)
(note: bit = binary digit)
0.8110 🡪 binary???
0.8110 =>
0.81 x 2 = 1.62
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
b)000110102
= 24 + 23 +21
= 16 + 8 + 2
= 2610
Binary and Octal
• From the stated theorem, the following is
a binary-octal conversion table.
Binary Octal Map using “421”
000 0
001 1 In a computer system,
010 2 the conversion from
011 3 binary to octal or
100 4 otherwise is based on
101 5 the conversion table
110 6 above.
111 7
3 digits in base-2 (binary) is equivalent to 1 digit in base-8 (octal)
Convert these binary numbers into octal numbers:
(a) 001011112 (8 bits) (b) 111101002 (8 bits)
= 578 = 3648
Binary and Hexadecimal
Binary Hexadecimal
0000 0
0001 1 Example: Use 7421
0010 2
0011 3 1.Convert the following binary
0100 4 numbers into hexadecimal numbers:
0101 5
0110 6 (a) 001011112
0111 7
1000 8 Refer to the binary-hexadecimal
1001 9 conversion table above
1010 A
1011 B 0010 11112 = 2F16
1100 C
1101 D 2 F
1110 E
1111 F
Example: Octal 🡪 Hexadecimal
Convert the following octal numbers into
hexadecimal numbers (16 bits)using, 7421
(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
Example: Hexadecimal 🡪 Binary
Refer to the binary-hexadecimal conversion table Refer to the binary-hexadecimal conversion table
1 2 B16 A B C D16
= 0001001010112 = 10101011110111102
Exercise 1
• Binary 🡪 decimal
• 001100
• 11100.011
• Decimal 🡪 binary
• 145
• 34.75
• Octal 🡪 hexadecimal
• 56558
Exercise 2
• Binary 🡪 decimal
• 110011.10011
• Decimal 🡪 binary
• 25.25
• Octal 🡪 hexadecimal
• 128
Ones Complement
• In the ones complement representation, positive
numbers are same as that of sign-and-magnitude
Example: +5 = 00000101 (8 bit)
⇒ as in sign-and-magnitude representation
Solution: Solution:
So,
(-10)10 = 1101012
Two’s complement
Solution:
✔First, obtain +5 representation in 8 bits ⇒
000001012
✔Obtain one’s complement for –5
⇒ 111110102
✔Add 1 to the ones complement number:
⇒ 111110102 + 12 = 111110112
✔–5 in two’s complement is 111110112
Exercise:
• Obtain representation of twos complement (6 bit)
for the following numbers
i) +710 ii)–1010
Solution: Solution:
(+10) 10 = 0010102
(+7) = 0001112
(same as sign-magnitude)
(-10) 10 = 1101012 + 12
= 1101102
So, twos compliment for –10 is
1101102
Exercise:
Obtain representation for the following
numbers
Decimal Sign-magnitude Twos complement
+7
+6
4 bits
-4
-6
-7
+18
-18 8 bits
-13
Binary Arithmetics
1. Addition ( + )
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10
1 + 1 + 1 = (1 + 1) + 1 = 10 + 1 = 112
Example:
i. 0101112 + 0111102 = 1101012
ii. 1000112 + 0111002 = 1111112
Example:
i. 0101112 - 0011102 = 0010012
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 One’s Complement, Two’s
Complement, sign-and-magnitude and floating point number