EEN 203 Slide Notes Year 2018: PART I - Numbers and Codes
EEN 203 Slide Notes Year 2018: PART I - Numbers and Codes
Year 2018
PART I – Numbers and Codes
Popular Number Systems
• Decimal: 𝑟 = 10. Digits are from 0 to 9.
Q. How to find out the code (number) given the value and the number
system or the radix?
A. Look closely how the code is evaluated.
𝑁 = 𝑑0 . 𝑟 0 + 𝑑1 . 𝑟1 + ⋯ + 𝑑𝑛 . 𝑟 𝑛
Number from Value
𝑁 = 𝑑0 . 𝑟 0 + 𝑑1 . 𝑟1 + ⋯ + 𝑑𝑛 . 𝑟 𝑛
Given the value 𝑁 and the radix 𝑟.
Required to find out the (𝑛 + 1) digits 𝑑𝑛 , 𝑑𝑛−1 , … 𝑑1 , 𝑑0 .
L4D1
Number from Value
𝑁 = 𝑑0 . 𝑟 0 + 𝑑1 . 𝑟1 + ⋯ + 𝑑𝑛 . 𝑟 𝑛
Given the value 𝑁 and the radix 𝑟.
Required to find out the (𝑛 + 1) digits 𝑑𝑛 , 𝑑𝑛−1 , … 𝑑1 , 𝑑0 .
A. Boardwork.
Binary: 10011001002
Octal: 11448
Hexadecimal: 26416
Number with Radix Point
𝑑2 𝑑1 𝑑0 . 𝑑−1 𝑑−2 𝑑−3
Q. How to find out the digits to the right of the radix point?
Number with Radix Point
𝑁 = 𝑑−1 . 𝑟 −1 + ⋯ + 𝑑−𝑛 . 𝑟 −𝑛
We can find the digits to the right side of the radix point by multiplying
the fractional value 𝑁 (decimal) by 𝑟 and taking out whole numbers
one by one. These whole numbers are basically the digits 𝑑−1 to 𝑑−𝑛 in
this order.
Number with Radix Point
𝑁 = 𝑑−1 . 𝑟 −1 + ⋯ + 𝑑−𝑛 . 𝑟 −𝑛
We can find the digits to the right side of the radix point by multiplying
the fractional value 𝑁 (decimal) by 𝑟 and taking out whole numbers
one by one. These whole numbers are basically the digits 𝑑−1 to 𝑑−𝑛 in
this order.
Hint: Try to represent in 𝑟1 base the largest digit of 𝑟2 base. Take bases
8 and 2, 9 and 3, 16 and 4.
Conversion from radix 𝑟1 to 𝑟2
78 = 1112
89 = 223
𝐹16 = 334
Conversion from radix 𝑟1 to 𝑟2
78 = 1112
89 = 223
𝐹16 = 334
Binary ՞ Octal
11010011 2 = 011 2 010 2 011 2 = 323 8
2731 8 = 010 2 111 2 011 2 001 2 = 10111011001 2
Conversion from radix 𝑟1 to 𝑟2
Binary ՞ Octal
11010011 2 = 011 2 010 2 011 2 = 323 8
2731 8 = 010 2 111 2 011 2 001 2 = 10111011001 2
Binary ՞ Hex
10111011001 2 = 0101 2 1101 2 1001 2 = 5𝐷9 16
𝐶0𝐷𝐸 16 = 1100 2 0000 2 1101 2 1110 2
= 1100000011011110 2
Conversion from radix 𝑟1 to 𝑟2
Octal ՞ Hex
16 ≠ 8𝑝
But both are powers of 2.
L5D1
Conversion from radix 𝑟1 to 𝑟2
Boardwork:
2.3 8 = 010.011 2
0.10101 2 = 0.52 8 = 0. 𝐴8 16
BCD and Excess-3 Codes
Decimal Numerals Binary Numerals Excess-3
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
L5D2
Addition and Subtraction of Numbers
Boardwork for:
• 𝑁 = +85 ֜ 010101012𝑆𝑀
• 𝑁 = −85 ֜ 110101012𝑆𝑀
Negative Numbers
Sign-Magnitude Representation
• Normally MSB is used to denote sign.
• 0 means positive and 1 means negative.
• 𝑁 = +85 ֜ 010101012𝑆𝑀
• 𝑁 = −85 ֜ 110101012𝑆𝑀
𝑁 ′ ′𝑟 = 𝑟 𝑛 𝑟 − 𝑁 ′
𝑟 = 𝑁 𝑟
Negative Numbers
Radix Complement Representation
𝑵′ 𝒓 = 𝒓𝒏 𝒓 − 𝑵 𝒓 is defined as the 𝑟-complement of an 𝑛 digit
number 𝑁 𝑟 .
𝑁 ′ ′𝑟 = 𝑟 𝑛 𝑟 − 𝑁 ′
𝑟 = 𝑁 𝑟
𝑁′ 𝑟 = 𝑟 𝑛
𝑟−1− 𝑁 𝑟+1
= 𝑞𝑞 … 𝑞 − 𝑑𝑛−1 𝑑𝑛−2 … 𝑑1 𝑑0 𝑟 +1
= 𝑑′𝑛−1 𝑑′𝑛−2 … 𝑑′1 𝑑′0 𝑟 + 1
Negative Numbers
Radix Complement Representation
2𝐶
1000 1000 = −8
2𝐶
1000 1000 = −8 Range of Values in 𝑛-bit 2C R
−(2𝑛−1 − 1) to (2𝑛−1 − 1)
Complement Representations
Positive
Number
Positive Negative
Quantity Quantity
Negative
Number
Complement Representations
Positive
Number
Positive Negative
Quantity Quantity
Negative
Number
Operation in 2C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001
𝑁𝐴2𝐶 = 01011111
𝑁−𝐵2𝐶 = 11000111
Operation in 2C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001
𝑁𝐴2𝐶 = 01011111
𝑁−𝐵2𝐶 = 11000111
𝑁𝑆2𝐶 = 100100110
Operation in 2C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001
𝑁𝐴2𝐶 = 01011111
𝑁−𝐵2𝐶 = 11000111
𝑁𝑆2𝐶 = 100100110
Positive
Overflow MSB
Number
Operation in 2C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001
𝑁𝐴2𝐶 = 01011111
𝑁−𝐵2𝐶 = 11000111
𝑁𝑆2𝐶 = 100100110
֜ 𝑆 = +38
Operation in 2C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001
֜ 𝑆 = +38
Operation in 2C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001
A
A
D
D
-B E
B 2’s Complement
R
Operation in 2C Representation
A
A
D
D
1’s Complement -B E
B +1 R
Operation in 1C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001
Operation in 1C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001
L7D2
Octal Sign Magnitude
• MSB = 0 to 3 are positive numbers
• MSB = 4 to 7 are negative numbers
Note the position numbers are taken reverse than conventional bit
number.
Hamming SEC Code
• Given Word = 10011010
• Hamming Code = 𝑃1 𝑃2 1𝑃4 001𝑃8 1010
𝑃1 : 10111 ՜ 0
𝑃2 : 10101 ՜ 1
𝑃4 : 0010 ՜ 1
𝑃8 : 1010 ՜ 0
Hamming SEC Code
• Given Word = 10011010
• Hamming Code = 𝑃1 𝑃2 1𝑃4 001𝑃8 1010
𝑃1 : 10111 ՜ 0
𝑃2 : 10101 ՜ 1 Hamming Code is 011100101010
𝑃4 : 0010 ՜ 1
𝑃8 : 1010 ՜ 0
Hamming SEC Code
To detect error in a single bit, we calculate check bits 𝐶1 , 𝐶2 , 𝐶4 , 𝐶8 , etc.
Whichever check bits are 1, we calculate the sum of those positions.
Single bit error is in that position of the Hamming Code word.
Hamming SEC Code
To detect error in a single bit, we calculate check bits 𝐶1 , 𝐶2 , 𝐶4 , 𝐶8 , etc.
Whichever check bits are 1, we calculate the sum of those positions.
Single bit error is in that position of the Hamming Code word.
𝐶1 : 010111 ՜ 0
𝐶2 : 110111 ՜ 1 Error bit is in position 2 + 8 = 10
𝐶4 : 10010 ՜ 0
𝐶8 : 01110 ՜ 1 L9P1