[go: up one dir, main page]

0% found this document useful (0 votes)
239 views78 pages

EEN 203 Slide Notes Year 2018: PART I - Numbers and Codes

The document discusses various number systems including binary, decimal, octal, and hexadecimal. It covers representing values in different number systems, converting between number systems, and representing negative numbers using sign-magnitude and radix complement representations. Key topics include place value, addition and subtraction in different bases, and handling radix points when converting between bases.

Uploaded by

SHIVAM CHOPRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
239 views78 pages

EEN 203 Slide Notes Year 2018: PART I - Numbers and Codes

The document discusses various number systems including binary, decimal, octal, and hexadecimal. It covers representing values in different number systems, converting between number systems, and representing negative numbers using sign-magnitude and radix complement representations. Key topics include place value, addition and subtraction in different bases, and handling radix points when converting between bases.

Uploaded by

SHIVAM CHOPRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

EEN 203 Slide Notes

Year 2018
PART I – Numbers and Codes
Popular Number Systems
• Decimal: 𝑟 = 10. Digits are from 0 to 9.

• Binary: 𝑟 = 2. Digits are 0 and 1. They are also called bits.

• Octal: 𝑟 = 8. Digits are from 0 to 7.

• Hexadecimal: 𝑟 = 16. Digits are from 0 to 9, A, B, C, D, E, F.


Popular Number Systems
The value twelve as represented in some popular number systems:

• Decimal – 1210 . N = 2.100 + 1.101


• Binary – 11002 . N = 0.20 + 0.21 + 1.22 + 1.23
• Octal – 148 . N = 4.80 + 1.81
• Hexadecimal – 𝐶16 . N = 12.160
Popular Number Systems
The value twenty seven as represented in some popular number
systems:

• Decimal – 2710 . N = 7.100 + 2.101


• Binary – 110112 . N = 1.20 + 1.21 + 0.22 + 1.23 + 1.24
• Octal – 338 . N = 3.80 + 3.81
• Hexadecimal – 1𝐵16 . N = 11.160 + 1.161
Number from Value
• Number is the positional sequence of digits representing a certain
value (quantity). It is basically a codified representation of the value.
• In decimal system, value and number are the same. It is a ‘direct’
coding.

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 .

Division of 𝑁 by 𝑟 will give remainder 𝑑0 and quotient Q1 = 𝑑1 . 𝑟 0 +


𝑑2 . 𝑟1 + ⋯ + 𝑑𝑛 . 𝑟 𝑛−1
Further division of 𝑄1 by 𝑟 will give remainder 𝑑1 and quotient Q 2 =
𝑑2 . 𝑟 0 + 𝑑3 . 𝑟1 + ⋯ + 𝑑𝑛 . 𝑟 𝑛−2
This way we can keep dividing until there is no more quotient, or
quotient becomes zero.
Number from Value
Q. Represent the quantity 612 in binary, octal and hexadecimal. OR
Convert 61210 to binary, octal and hexadecimal.

A. Boardwork.
Binary: 10011001002
Octal: 11448
Hexadecimal: 26416
Number with Radix Point
𝑑2 𝑑1 𝑑0 . 𝑑−1 𝑑−2 𝑑−3

Whole value Fractional value


Total is weighted sum of digits Total is weighted sum of digits
Positions have positive index Positions have negative index
Radix is raised to positive powers Radix is raised to negative powers
Number with Radix Point
𝑑2 𝑑1 𝑑0 . 𝑑−1 𝑑−2 𝑑−3

Whole value Fractional value


Total is weighted sum of digits Total is weighted sum of digits
Positions have positive index Positions have negative index
Radix is raised to positive powers Radix is raised to negative powers

Total value of the above number is


𝑁 = 𝑑0 . 𝑟 0 + 𝑑1 . 𝑟1 + 𝑑2 . 𝑟 2 + 𝑑−1 . 𝑟 −1 + 𝑑−2 . 𝑟 −2 + 𝑑−3 . 𝑟 −3
Number with Radix Point
𝑑2 𝑑1 𝑑0 . 𝑑−1 𝑑−2 𝑑−3

Whole value Fractional value


Total is weighted sum of digits Total is weighted sum of digits
Positions have positive index Positions have negative index
Radix is raised to positive powers Radix is raised to negative powers

Total value of the above number is


𝑁 = 𝑑0 . 𝑟 0 + 𝑑1 . 𝑟1 + 𝑑2 . 𝑟 2 + 𝑑−1 . 𝑟 −1 + 𝑑−2 . 𝑟 −2 + 𝑑−3 . 𝑟 −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.

Q. Convert 0.62510 to binary, octal and hexadecimal.


A. Boardwork.
Binary: 0.1012
Octal: 0.58 Hexadecimal: 0. 𝐴16
Conversion from radix 𝑟1 to 𝑟2

NUMBER SUM Decimal DIVIDE NUMBER


in 𝑟1 NUMBER in 𝑟2
Conversion from radix 𝑟1 to 𝑟2

Then one digit in 𝑟2 base needs 𝑝 digits in 𝑟1 base.


Conversion from radix 𝑟1 to 𝑟2

Then one digit in 𝑟2 base needs 𝑝 digits in 𝑟1 base.

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

Then one digit in 𝑟2 base needs 𝑝 digits in 𝑟1 base.

78 = 1112
89 = 223
𝐹16 = 334
Conversion from radix 𝑟1 to 𝑟2

Then one digit in 𝑟2 base needs 𝑝 digits in 𝑟1 base.

78 = 1112
89 = 223
𝐹16 = 334

Each digit of 𝑟2 base can be separately expanded into 𝑝 digits in 𝑟1 base.


𝑝 digits in 𝑟1 base can be clubbed into one digit in 𝑟2 base.
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
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.

Octal ՞ Binary ՞ Hex


1234 8 = 001 010 011 100 = 0010 1001 1100
= 29𝐶 16
𝐶0𝐷𝐸 16 = 1100 0000 1101 1110
= 001 100 000 011 011 110 = 140336 8
Conversion from radix 𝑟1 to 𝑟2

Q. How to do the conversions when there is radix point?


Conversion from radix 𝑟1 to 𝑟2

Q. How to do the conversions when there is radix point?


A. In the same way but grouping of digits start from right of the radix
point and zero padding is done to the far right if required.

L5D1
Conversion from radix 𝑟1 to 𝑟2

Q. How to do the conversions when there is radix point?


A. In the same way but grouping of digits start from right of the radix
point and zero padding is done to the far right if required.

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:

• Addition in binary, octal and hex

• Addition in BCD and Excess-3


Negative Numbers
Sign-Magnitude Representation
• Normally MSB is used to denote sign.
• 0 means positive and 1 means negative.
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
Sign-Magnitude Representation
• Normally MSB is used to denote sign.
• 0 means positive and 1 means negative.

• 𝑁 = +85 ֜ 010101012𝑆𝑀
• 𝑁 = −85 ֜ 110101012𝑆𝑀

• For 𝑛-bit number, magnitude is represented by (𝑛 − 1) bits. So range


of values is −(2𝑛 − 1) to (2𝑛 − 1).
Negative Numbers
Sign-Magnitude Representation
• Normally MSB is used to denote sign.
• 0 means positive and 1 means negative.

Two representations of zero:


• 000000002𝑆𝑀 = +0
• 100000002𝑆𝑀 = −0

Binary addition algorithm does not work.


Negative Numbers
Radix Complement Representation
𝑵′ 𝒓 = 𝒓𝒏 𝒓 − 𝑵 𝒓 is defined as the 𝑟-complement of an 𝑛 digit
number 𝑁 𝑟 .
Negative Numbers
Radix Complement Representation
𝑵′ 𝒓 = 𝒓𝒏 𝒓 − 𝑵 𝒓 is defined as the 𝑟-complement of an 𝑛 digit
number 𝑁 𝑟 .

𝑁 ′ ′𝑟 = 𝑟 𝑛 𝑟 − 𝑁 ′
𝑟 = 𝑁 𝑟
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

𝑁′ 𝑟 = 𝑟𝑛 𝑟 − 𝑁 𝑟 = 𝑑′𝑛−1 𝑑′𝑛−2 … 𝑑′1 𝑑′0 𝑟 +1


Negative Numbers
Radix Complement Representation

𝑁′ 𝑟 = 𝑟𝑛 𝑟 − 𝑁 𝑟 = 𝑑′𝑛−1 𝑑′𝑛−2 … 𝑑′1 𝑑′0 𝑟 +1

Step 1: Take the positive number 𝑁 𝑟 = 𝑑𝑛−1 𝑑𝑛−2 … 𝑑1 𝑑0 𝑟


Step 2: Complement each digit to get 𝑑′𝑛−1 𝑑′𝑛−2 … 𝑑′1 𝑑′0 𝑟
Step 3: Add 1 to the LSB.
Negative Numbers
Diminished Radix Complement Representation

𝑁′ 𝑟 = 𝑟𝑛 𝑟 −1− 𝑁 𝑟 = 𝑑′𝑛−1 𝑑′𝑛−2 … 𝑑′1 𝑑′0 𝑟

Step 1: Take the positive number 𝑁 𝑟 = 𝑑𝑛−1 𝑑𝑛−2 … 𝑑1 𝑑0 𝑟


Step 2: Complement each digit to get 𝑑′𝑛−1 𝑑′𝑛−2 … 𝑑′1 𝑑′0 𝑟
2C Representation
4-bit number
Value 𝑵 𝟐 𝑵′ 𝟐 Value
+1 0001
+2 0010
+3 0011
+4 0100
+5 0101
+6 0110
+7 0111
L7D1
2C Representation
4-bit number
Value 𝑵 𝟐 𝑵′ 𝟐 Value
+1 0001 1111 -1
+2 0010 1110 -2
+3 0011 1101 -3
+4 0100 1100 -4
+5 0101 1011 -5
+6 0110 1010 -6
+7 0111 1001 -7
2C Representation
4-bit number
Value 𝑵 𝟐 𝑵′ 𝟐 Value
+1 0001 1111 -1
+2 0010 1110 -2
+3 0011 1101 -3
+4 0100 1100 -4
+5 0101 1011 -5
+6 0110 1010 -6
+7 0111 1001 -7
2C Representation
4-bit number
Value 2C R of 2C R of Value
+1 0001 1111 -1
+2 0010 1110 -2
+3 0011 1101 -3
+4 0100 1100 -4
+5 0101 1011 -5
+6 0110 1010 -6
+7 0111 1001 -7
2C Representation
4-bit number
Value 2C R of 2C R of Value
+1 0001 1111 -1
+2 0010 1110 -2
0000 is +3 0011 1101 -3 1000 is
2C R of 0 +4 0100 1100 -4 2C R of -8
+5 0101 1011 -5
+6 0110 1010 -6
+7 0111 1001 -7
2C Representation
4-bit number
2𝐶
0000 10000 = 0000 (since we are dealing with 4-bit number)

No problem of two zeros.


2C Representation
4-bit number
2𝐶
0000 10000 = 0000 (since we are dealing with 4-bit number)

No problem of two zeros.

2𝐶
1000 1000 = −8

Extra negative number.


2C Representation
4-bit number
2𝐶
0000 10000 = 0000 (since we are dealing with 4-bit number)

No problem of two zeros.

2𝐶
1000 1000 = −8 Range of Values in 𝑛-bit 2C R

Extra negative number. −2𝑛−1 to (2𝑛−1 − 1)


1C Representation
4-bit number
Value 𝑵 𝟐 𝑵′ 𝟐 Value
+1 0001 1110 -1
+2 0010 1101 -2
+3 0011 1100 -3
+4 0100 1011 -4
+5 0101 1010 -5
+6 0110 1001 -6
+7 0111 1000 -7
1C Representation
4-bit number
Value 1C R of 1C R of Value
+1 0001 1110 -1
+2 0010 1101 -2
+3 0011 1100 -3
+4 0100 1011 -4
+5 0101 1010 -5
+6 0110 1001 -6
+7 0111 1000 -7
1C Representation
4-bit number
Value 1C R of 1C R of Value
+1 0001 1110 -1
+2 0010 1101 -2
0000 is 1C +3 0011 1100 -3 1111 is
R of +0 +4 0100 1011 -4 1C R of -0
+5 0101 1010 -5
+6 0110 1001 -6
+7 0111 1000 -7
1C Representation
4-bit number
No extra negative number.

Two zeros are present.


1C Representation
4-bit number
No extra negative number.

Two zeros are present.

Range of Values in 𝑛-bit 1C 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

𝑁𝐴2𝐶 = 01011111 𝑁−𝐴2𝐶 = 10100001


𝑁−𝐵2𝐶 = 11000111 𝑁𝐵2𝐶 = 00111001

𝑁𝑆2𝐶 = 100100110 𝑁𝑆2𝐶 = 11011010

֜ 𝑆 = +38
Operation in 2C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001

𝑁𝐴2𝐶 = 01011111 𝑁−𝐴2𝐶 = 10100001


𝑁−𝐵2𝐶 = 11000111 𝑁𝐵2𝐶 = 00111001

𝑁𝑆2𝐶 = 100100110 𝑁𝑆2𝐶 = 11011010


Negative
MSB
֜ 𝑆 = +38 Number
Operation in 2C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001

𝑁𝐴2𝐶 = 01011111 𝑁−𝐴2𝐶 = 10100001


𝑁−𝐵2𝐶 = 11000111 𝑁𝐵2𝐶 = 00111001

𝑁𝑆2𝐶 = 100100110 𝑁𝑆2𝐶 = 11011010


𝑁′𝑆2𝐶 = 00100101
֜ 𝑆 = +38 ֜ 𝑆 = −37
Operation in 2C Representation
𝑺=𝑨−𝑩>𝟎 𝑺=𝑩−𝑨<𝟎
𝐴 = 95 ֜ 𝑁𝐴 = 01011111 𝐴 = 95 ֜ 𝑁𝐴 = 01011111
𝐵 = 57 ֜ 𝑁𝐵 = 00111001 𝐵 = 57 ֜ 𝑁𝐵 = 00111001

𝑁𝐴2𝐶 = 01011111 𝑁−𝐴2𝐶 = 10100001


𝑁−𝐵2𝐶 = 11000111 𝑁𝐵2𝐶 = 00111001

𝑁𝑆2𝐶 = 100100110 𝑁𝑆2𝐶 = 11011010


𝑁′𝑆2𝐶 = 00100101 + 1
֜ 𝑆 = +38 ֜ 𝑆 = −38
Operation in 2C Representation

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

• Remaining (𝑛 − 1) digits give the magnitude

+85 ֜ 0125 = 1125 = 2125 = 3125 in 4 digits

−85 ֜ 4125 = 5125 = 6125 = 7125 in 4 digits


7 and 8 Complement Representation
• MSB = 0 to 3 are positive numbers
• MSB = 4 to 7 are negative numbers

• To do any operation, convert the MSB to the extreme value of 0 or 7.


• To find the negative number, take 7 or 8 complement of the
corresponding positive number.
• Do operations in the complement representation.
• To find result, take care of MSB to interpret result. Also take care to add
or discard overflow as the case may be.
Decimal Sign Magnitude
• MSB = 0 to 4 are positive numbers
• MSB = 5 to 9 are negative numbers

• Remaining (𝑛 − 1) digits give the magnitude

+85 ֜ 0085 = 1085 = 2085 = 3085 = 4085 in 4 digits

−85 ֜ 5085 = 6085 = 7085 = 8085 = 9085 in 4 digits


9 and 10 Complement Representation
• MSB = 0 to 4 are positive numbers
• MSB = 5 to 9 are negative numbers

• To do any operation, convert the MSB to the extreme value of 0 or 9.


• To find the negative number, take 9 or 10 complement of the
corresponding positive number.
• Do operations in the complement representation.
• To find result, take care of MSB to interpret result. Also take care to add
or discard overflow as the case may be.
Gray Code
• Unit change in value comes with single bit change in the binary word.
• Useful in encoding position numbers which change only by one
position unit.
Value Normal Binary Gray Code Value Normal Binary Gray Code
0 0000 0000 8 1000 1100
1 0001 0001 9 1001 1101
2 0010 0011 10 1010 1111
3 0011 0010 11 1011 1110
4 0100 0110 12 1100 1010
5 0101 0111 13 1101 1011
6 0110 0101 14 1110 1001
7 0111 0100 15 1111 1000
Parity Code
• Extra bit is added to indicate number of 1s in an 𝑛-bit word.

• Even Parity (default) = 0 if number of 1s is even, otherwise parity = 1.


• Odd Parity = 0 if number of 1s is odd, otherwise parity = 1.
Parity Code
• Extra bit is added to indicate number of 1s in an 𝑛-bit word.

• Even Parity (default) = 0 if number of 1s is even, otherwise parity = 1.


• Odd Parity = 0 if number of 1s is odd, otherwise parity = 1.
Binary Word Even Parity Odd Parity
011010101 1 0
1100110101 0 1
110 0 1
001101 1 0
011011 0 1
1101101 1 0
Parity Code
• Extra bit is added to indicate number of 1s in an 𝑛-bit word.

• Even Parity (default) = 0 if number of 1s is even, otherwise parity = 1.


• Odd Parity = 0 if number of 1s is odd, otherwise parity = 1.

• Useful to check integrity of code when odd number of bits are in


error.
• Fails to check code integrity if error is in even number of bits.
Hamming SEC Code
• A sequence of parity bits are calculated from the given binary word
• A consolidated Hamming Code is formed with the parity bits and the
binary word

• Given Word = 10011010


• Hamming Code = 𝑃1 𝑃2 1𝑃4 001𝑃8 1010
Hamming SEC Code
• A sequence of parity bits are calculated from the given binary word
• A consolidated Hamming Code is formed with the parity bits and the
binary word

• Given Word = 10011010


• Hamming Code = 𝑃1 𝑃2 1𝑃4 001𝑃8 1010

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

To calculate 𝑃𝑖 , take alternate 𝑖 number of bits starting from position of 𝑃𝑖


and calculate even parity of the bits.
Hamming SEC Code
• Given Word = 10011010
• Hamming Code = 𝑃1 𝑃2 1𝑃4 001𝑃8 1010

To calculate 𝑃𝑖 , take alternate 𝑖 number of bits starting from position of 𝑃𝑖


and calculate even parity of the bits.

𝑃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

To calculate 𝑃𝑖 , take alternate 𝑖 number of bits starting from position of 𝑃𝑖


and calculate even parity of the bits.

𝑃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.

Hamming Code is 011100101010. Let error word be 011100101110.

𝐶1 : 010111 ՜ 0
𝐶2 : 110111 ՜ 1 Error bit is in position 2 + 8 = 10
𝐶4 : 10010 ՜ 0
𝐶8 : 01110 ՜ 1 L9P1

You might also like