0% found this document useful (0 votes)
20 views

CMP241PART1&2

Binary codes

Uploaded by

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

CMP241PART1&2

Binary codes

Uploaded by

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

CMP 241: COMPUTER ELECTRONICS (2 UNITS)

NUMBER SYSTEM OPERATIONS AND CODES

Arithmetic operations using decimal numbers are quite common. However, in logical

design it is necessary to perform manipulations using the binary system of numbers

because of the on-off nature of the physical devices used. This lecture note explains the

fundamental concepts involved in dealing with number systems, the binary number

system and its relationship to other number systems such as decimal, hexadecimal and

octal. Arithmetic operations with binary numbers are covered in order to provide a basis

for understanding how computers and many other types of digital system work. The

difference between number systems is in the base number where a carry takes place. The

binary number system and digital codes are fundamental to computers and to digital

electronics in general. Also, digital codes such as Binary Coded Decimal (BCD), Gray

code and ASCII are covered. The parity method for detecting errors in code is introduced

and a method for correcting errors is described. A number system relates quantities and

symbols. The base or radix of a number system represents the number of digits or basic

symbols in that particular number system. For instance, the decimal number system has a

base of 10 because it is composed of the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

DECIMAL NUMBERS

In decimal number system, each of the ten digits (i.e. 0 through 9) represent a certain

quantity. The base is ten and each digit at each position in the number can have a value of

0 through 9. At the number 10, a carry is generated. The weight of each position is equal

to the base raised to the power of the position. The first position to the left of the decimal

1
point is the 0th position, the next is position 1, the next is position 2, position 3, and so

on. The weight of the 0 position is 10 to the 0 th power (100 = 1). The weight of the next

digit is 10 to the power of 1 (101=10), the next is 10 to the positional power of 2

(102=100), and so on.

Consider the number 1987. Seven is in the zero position, eight is in the 1 position, nine is

in the 2 position and one is in the 3 position. Each digit is multiplied by its positional

weight of 1000, 100, 10, 1. The decimal number 1987 is equivalent to 1000 + 900 + 80 +

7.

Weight 103 102 101 100 10-1

Position 3 2 1 0 -1

Decimal Number 1 9 8 7. 010

Base

The weights for whole numbers are positive powers of ten that inrease from right to left,

beginning with 100 = 1

………105 104 103 102 101 100

For fractional numbers, the weghts are negative powers of ten that decrease from left to

right beginning with 10-1

2
102 101 100. 10-1 10-2 10-3 ……….

The weight of a decimal number is the sum of the digits after each digit has been

multiplied by its weight.

Example 1. Express the decimal number 47 as the sum of the value of each digit.

Solution: The digit 4 has a weight of 10 which is 10 1 as indicated by its position. The

digit 7 has a weight of 1, which is 100, as indicated by its position.

47 = (4 × 101) + (7 × 100 )

= (4 × 10) + (7 × 1)

= 40 + 7

= 47

Related problem: Detemine the value of each digit in 939.

Example 2: Express the decimal number 568 as a sum of the values of each digit.

Solution : The whole number digit 5 has a weight of 100 which is 10 2 . The digit 6 has a

weight of 10 which is 101 . The digit 8 has a weight of 1 which is 100.

568 = (5 × 102) + (6 × 101) + (8 × 100)

= (5 × 100) + (6 × 10 ) + (8 × 1 )

= 500 + 60 + 8

= 568

Example 3: Express the decimal number 568.23 as a sum of the values of each digit.

Solution: The whole number digit 5 has a weight of 100 which is 10 2. The digit 6 has a

weight of 10 which is 101 . The digit 8 has a weight of 1 which is 10 0. The fractional digit

3
2 has a weight of 0.1, which is 10 -1 and the fractional digit 3 has a weight of 0.01 which is

10-2.

568.23 = (5 × 102) + (6 × 101) + (8 × 100) + (2 × 10-1) + (3 × 10-2)

= (5 × 100) + (6 × 10 ) + (8 × 1 ) + (2 × 0.1) + (3 × 0.01)

= 500 + 60 + 8 + 0.2 + 0.03

= 568.23

Related problem: Determine the value of each digit in 67.924.

BINARY NUMBER SYSTEM

A binary number system is a code that uses only two basic symbols. The digits are 0 and

1. The position of a 1 and a 0 in a binary number indicates its weight or value within the

number. The weight of a binary number is based on the powers of two. Also, the weight

of each binary digit commensurate with its position is equal to the base raised to the

power of that position. The binary number system is another way to represent quantities.

It is less complicated when compared to the decimal, octal and hexadecimal number

systems because it has only two digits hence, a base two system. The binary number

system has many advantages and is widely used in digital systems. The column weight

of decimal numbers are powers of 10 that increase from right to left beginning with 10 0 =

1;…….105 104 103 102 101 100. In binary, the number count is 0, 1 with a carry generated

at two; the base is equal to 2. Two raised to the power of 1 is 2. Two to the power of 2 is

4. Two raised to the power of 3 is 8. In binary, the weight of each digit’s position is twice

the value of the previous position such as 1, 2, 4, 8, 16, 32, 64, 128, and so on.

The binary equivalents for some decimal numbers are given below:

4
Decimal 0 1 2 3 4 5 6 7 8 9 10 11

Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011

Each digit in a binary number has a value or weight. The LSB has a value of 1.

The second from the right has a value of 2, the next 4, etc.

16 8 4 2 1

24 23 22 21 20

The base is two and written as (0011) 2 = 310 . In general, with n bits we can count up to a

number equal to 2n – 1.

COUNTING IN BINARY

To learn to count in the binary system, first look at how you count in the decimal system.

You start at zero and count up to nine before you run out of digits. You then start another

digit position (to the left) and continue counting 10 through 99. At this point you have

exhausted all two-digit combinations, so as a third digit position is needed to count from

100 through 999.

A comparable situation occurs when you count in binary, except that you have only two

digits called bits. Begin counting 0, 1. At this point you have used both digits, so include

another digit position and continue 10, 11. You have now exhausted all combinations of

two digits, so as a third position is required, with three digit positions you can continue to

count: 100, 101, 110 and 111. Now you need a fourth digit positions to continue and so

5
on. A binary count of zero through fifteen is shown in the table below. Note the pattern

with which the 1s and 0s alternate in each column.

DECIMAL

NUMBER BINARY NUMBER

0 0 0 0 0

1 0 0 0 1

2 0 0 1 0

3 0 0 1 1

4 0 1 0 0

5 0 1 0 1

6 0 1 1 0

7 0 1 1 1

8 1 0 0 0

9 1 0 0 1

10 1 0 1 0

11 1 0 1 1

12 1 1 0 0

13 1 1 0 1

14 1 1 1 0

15 1 1 1 1

6
As shown in the table above, four bits are required to count from 0 to 15. In general with

n bits, one can count up to a number equal to 2n – 1.

Largest decimal number = 2n – 1

For example, with five bits (n = 5) one can count from zero to thirty one:

25 – 1 = 32 – 1 = 31

With six bits (n =6) one can count from zero to sixty- three.

26 – 1 = 64 – 1 = 63

BINARY TO DECIMAL CONVERSION

The decimal value of any binary number can be found by adding the weight of all bits

that are 1 and discarding the weight of all bits that are 0.

Example1: Convert the binary whole number 1001 to decimal.

Solution:

(1001)2 = X10

(1001) 2 = 1x23+ 0x22 + 0x21 + 1x20

= 1× 8 + 0 ×4 + 0 × 2 + 1×1

= 8 + 0 + 0 + 1

(1001)2 = (9)10

Fractions:

For fractions, weights of the digit positions are written from the right of the binary

point starting with -1 in decreasing order. The first five weights are given as follows:

2-1 2-2 2-3 2-4 2-5

7
Example 2: Convert the fractional binary 0.0110 to decimal

Solution:

(0.0110)2 = X10

= 0x2-1+ 1× 2-2+ 1×2-3 + 0×2-4

= 0 x0.5 + 1x0.25 + 1x0.125 + 0x0.0625

= (0.375)10

Example 3: Convert the fractional binary 1011.101 to decimal.

Solution:

(1011.101)2 = X10

= 1 × 23+ 0 × 22 + 1 × 21 + 1×20 + 1× 2-1 + 0x2-2 + 1x2-3

= 8 +0 + 2 + 1 + 0.5 + 0 + 0.125

= (11.625)10

Related questions:

a. Convert the binary number 10010001 to decimal.

b. Convert the fractional binary number 10.111 to decimal.

DECIMAL TO BINARY CONVERSION

In decimal to binary conversion, the decimal number is divided by 2 progressively and

the remainder is written after each division. The remainders are then taken in the reverse

order to form the required binary number.

Example: Convert the following decimal numbers to binary:

8
(a) 12 (b) 21 (c) 25 (d) 58 (e) 82

Solution:

(a)

(12)10 = X2

(12)10 = (1100)2

(b)

(21)10 = X2

21 = 16 + 4 + 1 = 24 + 22 + 20 = 10101

(21)2 = (10101)10

CONVERTING DECIMAL FRACTIONS TO BINARY

The fraction is multiplied by 2 and the carry in the integer position is written after

each multiplication. Then they are written in the forward order to get the corresponding

binary equivalent.

Example:

(0.4375)10 = X2

2 x 0.4375 = 0.8750 => 0

2 x 0.8750 = 1.750 => 1

2 x 0. 750 = 1.5 => 1

2 x 0.5 = 1.0 => 1

(0.4375)10= (0.0111)2

OCTAL NUMBER SYSTEM

9
The octal number system consists of eight digits, 0 through 7. Octal number system has a

base of 8. First eight decimal digits 0, 1,2,3,4,5,6,7 are used in this system.

OCTAL BINARY

NUMBE NUMBER

0 000

1 001

2 010

3 011

4 100

5 101

6 110

7 111

OCTAL TO DECIMAL CONVERSION

In the octal number system, each digit correspond to the powers of 8. The weight of each

digital position in octal number is as follows:

84 83 82 81 80 8-1 8-2 8-3

10
To convert from octal to decimal, multiply each octal digit by its weight and add the

resulting products.

Example 1: Convert octal number 48 to a decimal number.

Solution:

(47)8 = X10

47 = 4 x 81 + 7 x 80

=4x8 +7x1

= 32 + 7

= 39

(48)8 = (39)10

Example 2: Convert the octal number 22.34 to a decimal number.

Solution:

(22.34)8 = X10

22.34 = 2 x 81 + 2 x 80 + 3 x 8-1 + 4 x 8-2

= 16 + 2 + 3 x 1/8 +4 x 1/64

= (18.4375)

(22.34)8 = (18.4375)10

DECIMAL TO OCTAL CONVERSION

Converting a decimal number to an octal number requires that the decimal number is

divided by 8 progressively such that for each division, the remainder is written and

finally the remainders are written in the reverse order to form the required octal number.

11
If the number has a fractional part, that part is multiplied by 8 and the carry in the integer

part is taken. Finally the carries are taken in the forward order.

Example: Convert the decimal number 19.11 to octal number.

Solution:

(19.11)10 = X8

0.11 x 8 = 0.88 => 0

0.88 x 8 = 7.04 => 7

0.04 x 8 = 0.32 => 0

0.32 x 8 = 2.56 => 2

0.56 x 8 = 4.48 => 4

(19.11)10 = (23.07024)8

OCTAL TO BINARY CONVERSION

Since the base of octal number is 8, i.e., the third power of 2, each octal number is

converted into its equivalent binary digit of length three.

Example 1: Convert the octal number 57 to its binary number equivalent.

Solution:

(57)8 = X2

Find the equivalent of 5 and 7 in binary and combine them together:

5 7

101 111

12
(57)8 = (101111)2

Example 2: Convert the fractional octal number 57.127 to binary number equivalent.

Solution:

(57.127)8 = X2

5 7 . 1 2 7

101 111 . 001 010 111

(57.127)8 = (101111.001010111)2

BINARY TO OCTAL CONVERSION

The given binary number is grouped into a group of 3 bits, starting at the octal point

and each group is converted into its octal equivalent.

Example 1: Convert the binary number 1110101101 to octal number equivalent.

Solution:

(1110101101)2 = X8

001 110 101 101

1 6 5 5

(1110101101)2 = 16558

Example 2: Convert the binary number 1101101.11101 to octal number.

Solution:

(1101101.11101)2 = X8

001 101 101 . 111 010

1 5 5 . 7 2

13
(1101101.11101)2 = (155.72)8

HEXADECIMAL NUMBER SYSTEM

The hexadecimal number system consists of 16 digits and characters. The hexadecimal

number system has a base of 16. It has 16 distinct symbols; the symbols from 0 through 9

are similarly used in decimal number system but with six more symbols needed, instead

of making new symbols, the alphabets A to F are used to represent what we call 10

through 15. One hexadecimal digit represents 4-binary digits, and its primary usefulness

is in simplifying bit patterns and making them easier to read. Each combination of 4 bits

is equivalent to a single hex digit.

Counting in hexadecimal works the same way as in octal or decimal except hex use 16

symbol per digit because each column multiplier is 16 larger than the previous column.

14
DECIMAL HEXADICMAL BINARY

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

BINARY TO HEXADECIMAL CONVERSION

Question 1: Convert the binary number 100101110 to its hexadecimal equivalent.

15
Solution: Starting from the right we group the digit into group of four (4). Each group of

binary is then converted into its equivalent hex symbol.

(100101110)2 = X16

0001 0010 1110

1 2 E

1001011102 = (12E)16

Question 2: Convert the binary number 11110101100110110000 to hexadecimal

equivalent.

Solution:

(11110101100110110000)2 = X16

1111 0101 1001 1011 0000

F 5 9 B 0

(11110101100110110000)2 = F59B016

Question3: Convert the fractional binary number 100101110.11011 to its hexadecimal

number equivalent.

Solution:

(100101110 . 11011) 2 = X16

Starting from the right of the binary point, we group the digits into groups of four (4).

Each group of binary is then converted into its equivalent hex symbol. Starting from the

left of the binary point (i.e. the fractional part), we group the digits into groups of four

(4).

0001 0010 1110 . 1101 1000

16
1 2 E . D 8

(100101110 . 11011)2 = (12E . D8)16

Related Problem: Convert binary number 11110101100110000 to hexadecimal number.

HEXADECIMAL TO BINARY CONVERSION

Since the base of every hexadecimal number is 16, i.e., the fourth power of 2, each

hexadecimal digit is converted into its equivalent binary digit of length four.

Example: Convert the hexadecimal number 5D.2A to binary number.

Solution:

(5D. 2A)16 = X2

5 D . 2 A

0101 1101 . 0010 1010

(5D. 2A)16 = (01011101.00101010)2

Related question: Convert the hexadecimal number F59B0 to its binary equivalent.

DECIMAL TO HEXADECIMAL CONVERSION

The decimal number is divided by 16, the remainders are safely kept after each division

and are finally written down in the reverse order. The fractional part is multiplied by 16

and carry in the integer part is taken in the forward order.

Example: Convert the decimal number 2479.859 to a hexadecimal number.

Solution:

(2479.859)10 = X16

17
16 x 0.859 = 13.744 => 13 (D)

16 x 0.744 = 11.904 => 11 (B)

16 x 0.904 = 14.464 => 14 (E)

16 x 0.464 = 7.424 => 7

16 x 0.424 = 6.784 => 6

(2479.859)10 = (9AF.DBE76)16

Related question: Convert the decimal number 45645 to its hexadecimal number

equivalent.

HEXADECIMAL TO DECIMAL

Each digit of the hexadecimal number is multiplied by its weight and then added.

Example: Convert the hexadecimal number 81.21 to its decimal number equivalent.

Solution:

(81.21)16 = X10

= 8 x 161 + 1 x 160+ 2 x 16-1 + 1 x 16-2

= 8 x 16 + 1 x 1 + 2/16 + 1/162

= (129.1289)10

(81.21)16 = (129.1289)10

18
Related Question: Convert the hexadecimal number D578.E2 to its decimal number

equivalent.

BINARY ARITHMETIC

There are 4 arithmetic operations that are exercised over binary numbers. They are:

 Binary addition

 Binary subtraction

 Binary multiplication

 Binary division

All arithmetic operations follow similar procedure as done using decimal numbers; i.e.

they possess a carry, borrow, etc.

BINARY ADDITION

The four basic rules for adding binary digits (bits) are as follows:

0 + 0 = 0; sum of 0 with a carry of 0

0 + 1 = 1; sum of 1 with a carry of 0

1 + 0 = 1; sum of 1 with a carry of 0

1 + 1 = 0; sum of 0 with a carry of 1

When binary numbers are added, the last condition creates a sum of 0 in a given column

and a carry of 1 over to the next column to the left as illustrated in the following addition

of 11 + 1:

11

01

100

19
Related problem: Find the sum of 1111 and 1100.

BINARY SUBTRACTION

To perform binary subtraction operation, the following binary subtraction rules should be

considered:

0–0=0

1–0=1

1–1=0

0 – 1 = 1 with a borrow of 1 is equivalent to 10 – 1 = 1

Example: Perform the following binary subtractions:

(a) 11 - 01 (b) 11 – 10 (c) 111 – 010 (d) Subtract 011 from 101

Solution:

(a) 11 (b) 11 (c) 111 (d) 101

- 01 -10 - 010 -011

____ _____ _____ 010

110 01 101

BINARY MULTIPLICATION

Binary multiplication of two bits is the same as multiplication of the decimal digits 0 and

1. The four basic rules for multiplying bits are as follows:

0×0=0

0×1=0

1×0=0

20
1×1=1

Example: Perform the following binary multiplications:

(a) 11 × 11 (b) 101 × 111

Solution:

(a) 11 (b) 111

× 11 ×101

11 111

+11 000

1001 111

100011

Related problem: Multiply 1101 by 1010.

BINARY DIVISION

The rules for binary division are as follows:

0÷1=0

1÷1=1

Similar to the decimal system, division by zero is meaningless. Division in binary follows

the same procedure as division in decimal.

Example: Perform the following binary divisions:

(a) 110 ÷ 11 (b) 110 ÷ 10 (c) 1001 ÷ 10

Solution:

10 11

(a) 11) 110 (b) 10) 110

21
11 10

000 10

10

00

Related problem: Divide 1100 by 100.

DIGITAL CODES

Many specialised codes are used in digital systems. Some codes are strictly numeric

while others are alphanumeric; that is, they are used to represent numbers, letters,

symbols and instructions. Several binary codes have evolved. Some of the known binary

codes are used to perform special functions such as error detection and correction. This

part of the lecture note discusses some of the numeric and alphanumeric binary codes.

BINARY CODED DECIMAL (BCD)

Binary Coded Decimal (BCD) expresses each of the decimal digits using a binary code.

There are only ten (10) unique code groups in the BCD system each meant for the unique

digits of the decimal number system. This makes it very easy to convert between decimal

and BCD. Because we naturally read and write in decimal, BCD code provides an

excellent interface to binary system. BCD is a four-bit weighted code which represents a

given decimal digit based on its assigned weight. BCD weighted code types are: 8421

BCD, 4221 BCD and 5421 BCD. Of all the BCD code types, 8421 BCD code is the most

popular and therefore simply referred to as the BCD code.

THE 8421 BCD CODE

22
The 8421 code is a type of BCD code. The designation of 8421 indicates the binary

weights of the four bits (23, 22, 21, 20). The ease of conversion between 8421 code

numbers and the familiar decimal numbers is the main advantage of this code. All you

must remember are the ten binary combinations that represent the ten decimal digits as

shown below. The 8421 code is the predominant BCD code. When we refer to BCD

code, we mean the 8421 code unless otherwise stated.

Invalid Codes: You should realise that with four bits, sixteen numbers (0000 through

1111) can be represented but in the 8421 code, only the first ten of these are used. The

last six code combinations that are not used - 1010, 1011, 1100, 1101, 1110, and 1111 are

called forbidden or invalid numbers in 8421 code. The following shows the decimal

numbers and their 8421 equivalent:

Decimal digit 0 1 2 3 4 5 6 7 8 9

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

DECIMAL TO BCD CODE CONVERSION

To express any decimal in BCD, simply replace each decimal digit with the appropriate

4-bit code, as shown in the example below:

Example: Convert each of the following decimal numbers to BCD

(a) 35 (b) 98 (c) 170 (d) 2469

Solution: (a) 3 5

0011 0101

35 = 00110101

23
(b) 9 8

1001 1000

98 = 10011000

(c) 1 7 0

0001 0111 0000

178 = 000101110000

(d) 2 4 6 9

0010 1000 0110 1001

2469 = 0010100001101001

Related Problem: Convert the decimal number 9673 to BCD.

BCD CODE TO DECIMAL CONVERSION

It is equally easy to determine a decimal number from a BCD number. Start at the right

most bit and break the code into groups of four bits. Then write the decimal digit

represented by each of the 4-bit group.

Example: Convert each of the following codes to decimal:

(a) 10000110 (b) 001101010001 (c) 1001010001110000

Solution: (a) 1000 0110

8 6

10000110 = 86

(b) 0011 0101 0001

3 5 1

351 = 001101010001

24
(c) 1001 0100 0111 0000

9 4 7 0

9470 = 1001010001110000

Related Problem: Convert the BCD code 1000001000100110110110 to decimal.

BCD ADDITION

BCD is a numerical code and as such, can be used in arithmetic operation. Addition is the

most important operation because other three operations (subtraction, multiplication, and

division) can be accomplished by the use of addition. Here is how to add BCD numbers:

Step 1. Add the two BCD numbers, using the rules for binary addition

Step 2. If a 4-bit sum is equal to or less than 9, it is a valid BCD number.

Step 3. If a 4-bit sum is greater than 9 or a carry out of the 4-bit group is generated, it is

an invalid result. Add 6 (0110) to the 4-bit sum in order to skip the six invalid states and

return the code to 8421. If a carry results when 6 is added, simply add the carry to the

next 4-bit group.

Example 1: Add the following BCD numbers:

(a) 0011 + 0100 (b) 0000011 + 00010101 (c) 10000110 + 00010011

(d) 010001010000 + 010000010111

Solution: The decimal number additions are shown for comparison purpose:

(a) 0011 3 (b) 0000 0011 03

+ 0100 +4 + 0001 0101 15

0111 7 0001 1000 18

25
Note that in each case, the sum in any 4-bit column does not exceed 9 (i.e. less than or

equal 9) and the 4-bit sums results are valid BCD numbers.

Example 2: Add the following BCD numbers:

(a) 1001 + 0100 (b) 1001 + 1001

(b) 00010110 + 00010101 (d) 01100111 + 01010011

Solution: The decimal number additions are shown for comparison purpose:

(a) 1001 9

+ 0100 +4

1101 Invalid BCD number (>9) 13

+ 0110 add 6 valid BCD number

0001 0011

1 3

(b) 1001 9

+ 1001 +9

1 0010 invalid because of carry 18

+ 0110 Add 6 Valid BCD number

0001 1000

1 8

(c) 0001 0110

+ 0001 0101

0010 1011 Right group is invalid (>9), 16

Left group is valid code. Add + 15

26
+ 0110 Add 6 to invalid code, Add 31

Carry, 0001, to next group,

0011 0001 Valid BCD number

3 1

(c) 0110 0111

+ 0101 0011

1011 1010 Both groups are invalid (>9), 67

+ 0110 + 0110 Add 6 to both groups valid BCD + 53

0001 0010 0000 number 120

1 2 0

Related Question: Add the BCD numbers 01001000+ 00110100.

NOTE:

In 8421 addition, if there is a carry or if it results in a forbidden group, then 0110 (6)

should be added in order to bring the result to the 8421 mode again.

Example 3:

8+ 1000 +

7 0111

15 1111

+ 0110

27
0001 0101

Example 4:

18 + 0001 1000 +

2 0000 0010

20 0001 1010

+ 0000 0110

0010 0000

GRAY CODE

Gray code is an unweighted and not arithmetic code; that is, there are no specific weights

assigned to the bit positions. The important feature of the gray code is that it exhibits only

a single bit change from one code word to the next in sequence. The property is important

in many applications, such as shaft position encoders, where error susceptibility increases

with the number of bit changes between adjacent numbers in sequence.

The table below lists a 4-bit gray code for decimal numbers 0 through 15. Binary

numbers are also shown in the table of reference. Like binary numbers, the gray code can

have any number of bits. Notice the single-bit change between successive Gray code

words. For instance, in going from decimal 3 to decimal 4, the Gray code changes from

0010 to 0110, while the binary code changes from 0011 to 0100, a change of three bits.

The only bit change is in the third bit from the right in the Gray code; the others remain

the same.

DECIMAL BINARY GRAY CODE

28
0 0000 0000

1 0001 0001

2 0010 0011

3 0011 0010

4 0100 0110

5 0101 0111

6 0110 0101

7 0111 0100

8 1000 1100

9 1001 1101

10 1010 1111

11 1011 1110

12 1100 1010

13 1101 1011

14 1110 1001

15 1111 1000

BINARY TO GRAY CODE CONVERSION

The following rules explain how to convert from binary number system to gray code

word:

1. The most significant bit (left-most) in the Gray code is the same as the

corresponding MSB in the binary number.

29
2. Going from left to right, add each adjacent pair of binary code bits to get the next

gray code bit. Discard carries.

For example, the conversion of the binary number 10110 to Gray code is as follows:

1 + 0 + 1 + 1 + 0 Binary

1 1 1 0 1 Gray

The Gray code is 11101.

GRAY TO BINARY CONVERSION

To convert from Gray to binary, the following rules apply:

1. The most significant bit (left most) in the binary code is the same as the

corresponding bit in the Gray code

2. Add each binary code bit generated to the gray code bit in the next adjacent

position. Discard carries.

For example, the conversion of the gray code word 11011 to binary is as follows:

1 1 0 1 1 Gray

+ + + +

1 0 0 1 0 Binary

30
The Binary number is 10010.

Examples:

(a) Convert the binary number 11000110 to Gray code

(b) Convert the Gray code 10101111 to binary

Solution (a) Binary to Gray code:

1 + 1 + 0 + 0 + 0 + 1 + 1 + 0

1 0 1 0 0 1 0 1

b) Gray code to Binary

1 0 1 0 1 1 1 1

× × × × × × ×

1 1 0 0 ` 1 0 1 0

ALPHANUMERIC CODES

In order to communicate, you need not only numbers, but also letters and other symbols.

In the strictest sense, alphanumeric codes are codes that represent numbers and

alphanumeric characters (letters). Most such code, also represent other characters such as

symbols and various instructions necessary for conveying information.

Computers, printers and other devices must process both alphabetic and numeric

information. Serial coding systems have been developed to represent alphanumeric

information as a series of 1’s and 0’s. The characters to be coded are alphabets (26

letters), numerals (10 decimal digits) for a total of 36 items and special characters such as

+,-, /,*, $, etc. This number requires six bits in each code combination because five bits

31
are insufficient (25 = 32). There are 64 total combinations of six bits, so there are 28

unused code combinations. Obviously in many applications, symbols other than just

numbers and alphabets are necessary to communicate completely. You need spaces,

periods, colons, semicolons, question marks, etc. You also need instructions to tell the

receiving systems what to do with the received information. With codes that are six bits

long, you can handle decimal numbers, the alphabet and a few (i.e. 28) other symbols.

This should give you an idea of the requirement for a basic alphanumeric code. The

ASCII is the most common alphanumeric code.

In order to code a character, a string of binary digits are used. In order to ensure

uniformity in coding, many codes have been developed some of which include:

1. ASCII: American Standard Code for Information Interchange.

2. EBCDIC: Extended Binary Coded Decimal Interchange Code: It is an 8 bit code.

3. Unicode.

ASCII

ASCII is the abbreviation for American Standard Code for Information Interchange.

Pronounced “askee”, ASCII is a universally accepted alphanumeric code used in most

computers and other related electronic equipment. Most computer keyboards are

standardized with ASCII. When you enter a letter, number or control command, the

corresponding ASCII code goes into the computer. Computers can only understand

binary numbers so an ASCII code is the numerical representation of a character such as

'a' or '@' or an action of some sort. ASCII was developed a long time ago and now the

non-printing characters are rarely used for their original purpose.

32
ASCII caters for 128 characters and symbols represented by a 7 bit binary code. Actually,

ASCII can be considered an 8-bit code with the MSB always 0(which is an extension of

the original 7-bit ASCII code). This 8-bit code is 00 through 7F in hexadecimal. The first

thirty two ASCII characters are non-graphic commands that are never printed or

displayed and are used only for control purposes. Example of the control characters are

“null,” “line feed,” “start of text,” and “escape,” The other characters are graphic symbols

that can be printed or displayed and include the letters of the alphabet (lowercase and

uppercase), the ten decimal digits, punctuation signs and other commonly used symbol.

EBCDIC

EBCDIC code is another widely used alphanumeric code mainly popular in larger

computer systems i.e. mainframes. It was created by IBM in order to extend the BCD

thereby making it relatively easier to enter data into mainframes by the use of punch

cards.

EBCDIC is an 8-bit code which is capable of accommodating up to 256 characters.

UNICODE

ASCII and EBCDIC do not have sufficient number of characters to be able to encode

alphanumeric data of all forms, scripts and languages. Furthermore, these encodings

suffer from incompatibility.

To overcome the above stated shortcomings, Unicode came into being. Unicode is the

most complete character encoding scheme that virtually allow text of all forms and

languages to be encoded for use by computers. Unicode also support a comprehensive set

33
of mathematical and technical symbols thereby simplifying any scientific information

exchange.

The 32-bit Unicode is the most recent. It is divided into 2 16 subsets with each subset

having 216 characters.

ERROR DETECTION AND CORRECTION CODES

When digital signals (group of 0s and 1s) are transmitted from one circuit or system to

another circuit or system, error may occur during transmission. The change of 1 to 0 or a

0 to 1 during transmission is known as error. It is necessary to detect and correct error in

order to obtain correct message.

A number of codes exist for detection and correction of error in digital transmission. The

concept of parity of a group of bits or digital word is the key for error detection and

correction.

Two methods for adding bits to codes to either detect a single-bit error or detect and

correct a single-bit error are discussed. The parity method of error detection is

introduced, and the hamming method of single-error detection and correction is covered.

When a bit in a given code word is found to be erratic, it can be corrected by simply

inverting it.

PARITY METHOD FOR ERROR DETECTION

Many systems use a parity bit as a means for bit error detection. Any group of bits

contain either an even or an odd number of 1’s. A parity bit is attached to a group of bits

in order to make the total number of 1s in a group always even or always odd. An even

34
parity bit makes the total number of 1’s even and an odd parity bit makes the total

number of 1’s odd.

A given system operates with even or odd parity, but not both. For instance, if a system

operates with even parity, a check is made on each group of bits received to make sure

the total number of 1’s in that group is even. If there is an odd number of 1’s, an error has

occurred.

As an illustration of how parity bits are attached to a code, the table below list the parity

bits for each BCD number for both even and odd parity. The parity bit for each BCD

number is the P column.

EVEN PARITY ODD PARITY

P BCD P BCD

0 0000 1 0000

1 0001 0 0001

1 0010 0 0010

0 0011 1 0011

1 0100 0 0100

0 0101 1 0101

0 0110 1 0110

1 0111 0 0111

35
1 1000 0 1000

0 1001 1 1001

The parity bit can be attached to the code either at the beginning or at the end depending

on the system’s design such that the total number of 1’s including the parity bit is always

even for even parity and always odd for odd parity.

Detecting an Error: A parity bit provides for the detection of a single bit error (or any

odd number of errors, which is very unlikely) but cannot check for two errors in one

group. For instance, let’s assume that we wish to transmit the BCD code 0101. (Parity

can be used with any number of bits; we are using four-bit code for illustration.) The total

code transmitted, including the even parity bit, is

Even parity bit

00101

BCD code

Now let’s assume that an error occurs in the third bit from the left (the 1 becomes a 0)

Even parity bit

00001

36
Bit error

When this code is received, the parity check circuitry determines that there is only a

single 1 (odd number) when there should be an even number of 1s. For this reason (i.e.

even number of 1’s does not appear in the code when it was received), an error is

indicated.

An odd parity bit also provides in a similar manner for the detection of a single error in a

given group of bits.

Example: Assign the proper even parity bit to the following code groups:

(a) 1010 (b) 111000 (c) 101101 (d) 1000111001001 (e) 1101101011111

Solution: Make the parity bit either 1 or 0 as necessary to make the total number of 1s

even. The parity bit will be the left- most bits.

(a) 01010 (b) 1111000 (c) 0101101 (d) 0100011100101 (d) 01101101011111

Related Question: Add an even parity bit to the 7-bit ASCII code for the letter K.

Example: An odd parity system receives the following code groups: 10110, 11010,

110011, 110101110100 and 1100010101010. Determine which group, if any, are in error.

Solution: Since odd parity is required, any group with an even number of 1’s is

incorrect. The following incorrect groups are: 110011 and 1100010101010.

Related Question: The following ASCII character is received by an odd parity system:

00110111. Is it correct?

THE HAMMING CODE

37
Hamming code not only provides for the detection of a bit error but also identifies the bit

that is in error so that it can be corrected. The code uses a number of parity bits

(dependant on the number of information bits) located at certain positions in the

information bits. As you have seen, a single parity bit allow for the detection of single-bit

error in a code word. A single parity bit can indicate that there is an error in a certain

group of bits. In order to correct a detected error, more information is required because

the position of the bit in error must be identified before it can be corrected. More than one

parity bit must be included in a group of bits to be able to correct a detected error. In a 7-

bit code, there are seven possible single-bit errors. In this case, three parity bits can not

only detect an error but can specify the position of the bit in error. The hamming code

provides for single error correction. The following coverage illustrates the construction of

a 7-hamming code for single-error correction.

Number of parity Bits: if the number of data bits is designed d, then the number of

parity bits, p, is determined by the following relationship:

2p ≥ d + p + 1………….. (1)

For example, if we have four data (information) bits, then p is found by trial and error

from Equation 1:

Let p = 2. Then

2p = 22 = 4

And

d + p + 1 = 4+2+1 = 7

38
Since 2p must be equal to or greater than d + p + 1, the relationship in equation 1 is not

satisfied. We have to try again. Let p = 3. Then

2p = 23 = 8

And

d+p+1=4+3+1=8

This value of p satisfies the relationship of equation 1, so three parity bits are required to

provide single error correction for four data (information) bits. It should be noted that

here, error detection and correction are provided for all bits (i.e. both parity and data

(information) bits) in a code group; that is, the parity bits also check themselves.

DETECTING AND CORRECTING AN ERROR WITH A HAMMING CODE

Each parity bit along with its corresponding group of bits must be checked for the proper

parity. If there are three parity bits in a code word, then three parity checks are made. If

there are four parity bits, then four parity checks must be made, and so on. Each parity

check will yield a good or bad result. The total result of all the parity check indicates the

bit, if any, that is in error, as follows:

Step1. Start with the group checked by P1.

Step 2. Check the group for proper parity. A 0 represents a good parity check, and 1

represents a bad check.

Step 3. Repeat step 2 for each parity group.

Step 4. The binary number formed by the results of all the parity checks describes the

position of the code bit that is in error. This is the error position code. The first parity

check generates the least significant bit (LSB). If all checks are good, there is no error.

39
Example: Assume that the code word in Example above (0011001) is transmitted and

that 0010001 is received. The receiver does not “know” that was transmitted and must

look for proper parities to determine if the code is correct. Describe any error that has

occurred in transmission if even parity is used.

Solution: First, make a bit position table, as indicated in table below:

BIT DESIGNATION P1 P2 D1 P3 D2 D3 D4

BIT POSITION 1 2 3 4 5 6 7

BINARY POSITION 001 010 011 100 101 110 111

Received code 0 0 1 0 0 0 1

First parity check

Bit P1 checks positions 1, 3, 5 and 7

There are two 1’s in this group

Parity check is good---------------------------------------------------------------- 0 (LSB)

Second parity check:

Bit P2 check positions 2, 3, 6 and 7

There are two 1’s in this group.

Parity check is good------------------------------------------------------------------------ 0

Third parity check:

Bit P3 check positions 4, 5, 6 and 7.

There is one 1 in this group.

Parity check is bad---------------------------------------------------------------------1(MSB)


40
Result:

The error position code is 100 (binary four). This says that the bit in position 4 is in error.

It is a 0 and should be 1. The corrected code is 0011001, which agrees with the

transmitted code.

Related Question: Repeat the process illustrated in the example if the received code is

0111001.

Example: The code 101101010 is received with errors. There are four parity bits, and

odd parity is used.

Solution: First make a bit position table shown below:

BIT DESIGNATION P1 P2 D1 P3 D2 D3 D4 P5 D5

BIT POSITION 1 2 3 4 5 6 7 8 9

BINARY POSITION 0001 0010 0011 0100 0101 011 0111 100 1001

NUMBER 0 0

Received code 1 0 1 1 0 1 0 1 0

First parity check:

Bit P1 check positions 1, 3, 5, 7 and 9

There are two 1’s in this group.

Parity check is bad. ------------------------------------------------- 1 (LSB)

Second parity check:

Bit P3 checks position 2, 3, 6, and 7.


41
There are two 1’s in this group.

Parity check is bad. -------------------------------------------- 1

Third parity check:

Bit P3 checks position 4, 5, 6 and 7.

There are two 1s in this group.

Parity check is bad. ---------------------------------------------- 1

Fourth parity check:

Bit P4 check positions 8 and 9.

There is one 1 in this group

Parity check is good. --------------------------------------------------- 0 (MSB)

Result:

The error position code is 0111 (binary seven). This says that the bit in position 7 is in

error. The corrected code is therefore 101101110.

Related Question: The code 101111001 is received. Correct any error if odd parity is

used.

ELEMENTARY CIRCUITS: LOGIC GATES

The most basic elements of digital circuits are logic gates. The most basic types of

electronic circuit designed with active devices such as diodes, transistors, etc consists of

gates. In its basic form, logic is the area of human reasoning that indicates certain

proposition (declarative statement) is true if certain conditions or premises are true. For

example ‘the light is on’, ‘the tube is operative’, ‘the switch is on’ and power supply is

available’ are the examples of propositions that can be classified as true or false. Several

42
propositions when combined give rise to propositional or logic functions. For example

the propositional statement ‘the light is on’ will be true if ‘the tube is operative’, ‘the

switch is on’ and ‘power supply is available’. This logical statements can be made as

follows:

The light is on if and only if the tube is operative, the switch is on and power supply is

available.

In the above example, the first statement is true only if the last three statements are true.

The first statement i.e. the light is on is then the basic proposition and the other three

statements are the conditions or premises upon which the proposition depends.

Many situations, processes and problems that we come across in our daily lives may be

expressed in the form of propositional or logic functions. As these are true /false, yes/no

statements, digital circuits with their two-state characteristic are quite suitable.

Boolean algebra, named after its pioneer George Boole (1816-65), is the algebra of logic

applied in the design and analysis of digital systems. The rules of this algebra are based

on human reasoning. It originated from the study of how we reason, what lines of

reasoning are valid and constitutes proof etc. Boolean algebra is a mathematical system

of logic in which truth functions are expressed as symbols and then these symbols are

manipulated to arrive at conclusion.

Boolean functions can be performed by digital circuits. Circuits that perform complicated

Boolean functions can be subdivided into simpler circuits that perform simpler Boolean

function. The circuits that perform the simplest Boolean functions are taken as basic

element, called logic gates and are represented by specialised symbols. The logic gates

43
are identified by the adjective representing the operation they perform. The most

common logic gates are the OR, AND, NOT, NAND, NOR, Exclusive OR and Exclusive

NOR gates. The NAND and NOR are called universal gates. NOT gate or inverter is the

only nontrivial single input gates.

Each gate is given several input signals to act upon. Its output may be high (logic- 1) or

low (logic 0) with respect to the voltage levels. The output depends upon the combination

of high and low inputs and the type of gate used. Since gates have the ability to make

logic decisions by producing a particular output under certain input conditions, they are

commonly called logic gate. The interconnection of gates to provide a prescribed output

is called a logic design. By combining thousands or millions of logic gates, it is possible

to perform highly complex operations. The maximum number of logic gates on an

integrated circuit is determined by the size of the chip divided by the size of the logic

gates. Since transistors make up most of the logic gates in computer processors, smaller

transistors mean more complex and faster processors.

AND GATE

The AND gate is one of the basic gates that can be combined to form any logic function.

Remember that a gate is simply an electronic circuit which operates one or more signals

to produce an output signal. The result of the output is high only for certain combination

of input signals.

The AND gate is composed of two or more inputs and a single output as indicated by the

standard logic symbol in the figure below. Inputs are on the left, and the output is on the

right in each symbol. An AND gate can have more than one number of inputs.

44
Logically, an AND gate (Figure below) has a high output only when all inputs are high.

The output is low when any one input is low.

AND Gate Figure

Boolean expression for the above AND gate operation is represented by the following

equation: Y=A.B

By definition of the logical AND operation Y = 1 if and only if A and B are equal to 1.

Otherwise, the result of the logical operation is 0. This information can simply be

represented in tabular form.

OPERATION OF AN AND GATE

An AND gate produces a HIGH output (1) only when all of the input are HIGH (1).

When any of the input is LOW (0), the output is LOW (0). Therefore, the basic purpose

of an AND gate is to determine when certain conditions are simultaneously true, as

indicated by HIGH levels on all of its inputs, and to produce a HIGH on its output to

indicate that all these conditions are true. The inputs of the 2 – input AND gate in the

figure above are labelled A and B while the output is labelled Y = A.B. The AND gate

operation can be stated as follows: For a 2-input AND gate, output Y = A.B is HIGH

only when inputs A and B are HIGH; Y = AB is LOW when either A or B is LOW or

when both A and B are LOW.

45
AND GATE TRUTH TABLE

The logical operation of a gate can be expressed using a truth table that lists all input

combinations with their corresponding outputs as illustrated in the table below for a 2-

input AND gate. The truth table can be expanded to any number of inputs. Although the

items HIGH are equivalent to a 1 and a LOW is equivalent to a 0 in positive logic. For

any AND gate, regardless of the number of inputs, the output is HIGH only when all

inputs are HIGH.

INPUT INPUT OUTPUT

A B Y = A.B

0 0 0

0 1 0

1 0 0

1 1 1

1 = HIGH, 0 = LOW

Such table is called truth table. The dot symbol is used to identify the AND function; an

inspection of the truth table reveals this choice to be an appropriate one if we permit

ourselves for the moment to treat the dot as multiplication. Obviously, the logical AND

operation resembles multiplication.

46
The total number of possible combinations of binary inputs to a gate is determined by the

following formula:

N = 2n -------------- equation (1)

Where N is the number of possible input combinations and n is the number of input

variables. To illustrate,

For two input variables: N = 22 = 4 combinations

For three input variables: N = 23 = 8 combinations

For four input variables: N = 24 =16 combinations

You can determine the number of input bit combinations for gates with any number of

inputs by using equation 1.

OR GATE

The OR gate is another type of the basic gates from which all logic functions may be

constructed. The OR gate performs logical addition more commonly known as the OR

function. An OR gate has two or more input signals with only one output signal. An OR

gate (Figure below) produces a high output (e.g. voltage) when any or the entire inputs

(e.g. input voltages) are high. The output is low only when all the inputs are low.

OR Gate Figure

The Boolean expression for the above OR gate is represented by the equation:

47
Y= A + B

By definition of the logical OR operation, Y = 1 if A = 1 or B = 1; otherwise, Y = 0. The

operation of a 2-input OR gate is described in the table below. This truth table can be

expanded to accomodate any number of inputs; regardless of the number of inputs, the

output is HIGH when one or more of the inputs are HIGH. The truth table for the OR

function is shown below:

A B Y = A+B

0 0 0

0 1 1

1 0 1

1 1 1

HIGH =1, LOW = 0

The study of the above truth table reveals that the logical OR operation resembles

addition.

LOGICAL EXPRESSION FOR AN OR GATE

The logical OR function of two variables A, B is represented mathematically between the

two variables, say, A + B.

Addition in Boolean algebra involves values that are either binary 1 or binary 0. The

basic rules for Boolean addition are as follows:

48
0+0=0

0+1=1

1+0=1

1+1=1

BOOLEAN ADDITION IS THE SAME AS THE OR FUNCTION

Note that Boolean addition differs from binary addition in the case where two 1’s are

added. There is no carry in Boolean addition.

The operation of a 2-input OR gate can be expressed as follows: if one input variable is

A, the other input variable is B and the output variable is X, then the Boolean expression

is:

A+B=X

To extend the OR expression so that more than two input variables are accomodated, a

new alphabet is used for each additional variable. For instance, the function of a 3-input

OR gate can be expressed as X = A + B + C. The expression for a 4- input OR gate can

be written as X = A + B + C + D and so on.

OR gate operation can be evaluated by using the Boolean expression for the output X by

substituting all possible combinations of 1 and 0 values, as shown in the table below for a

2-input OR gate. This evaluation shows that the output of an OR gate is a 1 (HIGH) when

any one or more of the inputs are 1 (HIGH). A similar analysis can be extended to OR

gates with any number of input variables.

A B A+B=X

0 0 0+0=0

49
0 1 0+1=1

1 0 1+0=1

1 1 1+1=1

NOT GATE

The NOT function is the logical operation of negation. A NOT gate (Figure below) is

also called an inverter. It provides the opposite state of whatever it may be. The circuit

has one input and one output. The output is the complement of the input. If the input

signal is high, the output is low and vice versa. It is interesting to note that the NOT

operation is not part of ordinary arithmetic or algebra.

NOT gate Figure

The Boolean expression for NOT gate is represented by the equation:

Y=Ā

It is read ‘Y equals the complement of A’.

When a HIGH level is applied to an inverter input, a LOW level will appear on its output.

When a LOW level is applied to its input, a HIGH will appear on its output. This

operation is summarized in the table below which shows the output for each possible

input in terms of levels and corresponding bits. A table such as this is called a truth table.

A Ā

0 1
50
1 0
If two NOT gates are cascaded then the output will be same as the input and the

circuit is called buffer circuit.

LOGICAL EXPRESSION FOR A NOT GATE (INVERTER)

In Boolean algebra which is the mathematics of logic circuits, a variable is designated by

a letter. The complement of a variable is designed by a bar over the letter. A variable can

take on a value of either 1 or 0. If a given variable is 1, its complement is 0 and vice

versa. Boolean algebra uses variables and operators to describe logic circuits.

The operation of an inverter (NOT circuits) can be expressed as follows: if the input

variable is called A and the output variable is called X, then:

X = A’

This operation states that the output is the complement of the input, so if A = 0, then X =

1, and if A = 1, then X = 0. The complemented variable A’ can be read as “ A bar “or not

A.

NAND GATE

A NAND gate is regarded as a universal gate due to the fact that any digital system can

be implemented from a combination of it. A NAND (Figure below) gate has two or more

input signals which results to only one output signal. All input signals must be high to get

a low output. When one AND gate is combined with a NOT gate, a NAND gate is

obtained. As such, this implies that an AND gate with complemented (inverted) output

gives the same result as a NAND gate. In the NAND gate, output is low only when all

51
inputs are high. A standard logic symbol for a 2-input AND and NOT gates as well as

NAND gate are shown in the figures below:

NAND gate Figure

The standard symbol for the NAND gate is the same as AND gate symbol except for a

small circle denoting the inversion operation. Thus, the NAND gate operates like AND

gate followed by an INVERTER so the circuits shown above are equivalent.

The truth table for NAND function is given below:

A B Y=A.B

0 0 1

0 1 1

1 0 1

52
1 1 0

OPERATION OF A NAND GATE

A NAND gate produces a LOW output only when all the inputs are HIGH. When any of

the inputs is LOW, the output will be HIGH. For the specific case of a 2-input NAND

gate as shown above with the inputs labelled A, B and the output labelled X, the

operation can be stated as follows: for a 2-input NAND gate, output X is LOW if inputs

A and B are HIGH; X is HIGH if either A or B or both is/are LOW.

NOR GATE

The term NOR is a contraction of NOT-OR and implies an OR function with an inverted

output. Similar to NAND gate, the NOR gate is also a useful logic element regarded as

universal gate because it can be used in several combinations to perform AND, OR and

inverter operations. NOR gate (Figure below) has two or more input signals and one

output signal. It consists of one OR gate followed by an inverter. A NOR gate produces a

high output only when all the inputs (voltages) are low. A standard logic symbol for 2-

input NOR gate and the equivalent OR gate followed by an INVERTER are shown

below:

53
NOR gate figures

The standard symbol for the NOR gate is the same as the OR gate symbol except that it

has a small circle on the output. This small circle represents the inversion operation.

Thus, the NOR gate operates like an OR gate followed by an inverter.

The truth table for NOR function is given below:

A B ____

Y=A+B

0 0 1

0 1 0

1 0 0

1 1 0

XOR GATE

The XOR gate is one of the two special logic circuits that occur quite often in digital

systems. XOR (Figure below) gate is an abbreviation of exclusive OR gate. For a two

input XOR gate, the output is high when all the inputs are different and the output is low

when all the inputs are same. This means the output of an XOR gate is true only when

54
exactly one of its inputs is true. If both of an XOR gate's inputs are false, or if both of its

inputs are true, then the output of the XOR gate is false. In general, the output of an XOR

gate is high when the number of its high inputs are odd.

Exclusive disjunction or exclusive-OR is a logical operation that outputs true only when

both inputs differ (one is true, the other is false). Exclusive disjunction essentially means

'either one, but not both'. In other words, if and only if one is true, the other cannot be

true.

3-input Ex-OR Gate

The Boolean expression for the 2-input XOR gate is:

Y= A’.B A.B’

For an exclusive-OR gate, output X is HIGH if input A is low and Input B is HIGH, or if

input A is HIGH and input B is low; Y is LOW if A and B are both HIGH or both LOW.

Logic Diagram

55
Truth Table for a 2-input XOR gate:

A B Y =A + B

0 0 0

0 1 1

1 0 1

1 1 0

Truth Table for a 3-input XOR gate:

SYMBOL TRUTH TABLE

A B C Q

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 0

1 0 0 1

56
1 0 1 0

1 1 0 0

1 1 1 1

“Any ODD Number of Inputs”

gives Q = 1

Boolean Expression Q =

A B C

EXCLUSIVE-NOR GATE (XNOR)

The Exclusive-NOR Gate function or Ex-NOR for short is a digital logic gate that is the

reverse or complementary form of the Exclusive-OR function we looked at previously.

Basically, the “Exclusive-NOR Gate” is a combination of the Exclusive-OR gate and the

NOT gate but has a truth table similar to the standard NOR gate in that it has an output

that is normally at logic level “1” and goes “LOW” to logic level “0” when ANY of its

inputs are at logic level “1”. There are 2 symbols for XNOR gates: the 'distinctive'

symbol and the 'rectangular' symbol. For more information see Logic Gate Symbols. The

ANSI symbol for the XNOR gate is a standard XOR gate with an inversion bubble

57
connected. The two-input version implements logical equality, behaving according to the

truth table shown below. A HIGH output (1) results if both of the inputs to the gate are

the same. If one but not both inputs are HIGH (1), a LOW output (0) results.

Ex-NOR gate equivalent:

Boolean Expression Q = (A+B)’

Standard symbols for an exclusive- NOR (XNOR):

"Distinctive" XNOR symbol

"Rectangular" XNOR Symbol

The XNOR gate with inputs A and B implements the logical expression:

58
Truth Table for a 2-input XNOR gate:

INPUT OUTPUT

A B A XNOR B

0 0 1

0 1 0

1 0 0

1 1 1

If no specific XNOR gates are available, one can be made from four NOR does gates or

five NAND gate in the configurations shown below. In fact, any logic gate can be made

from combinations of only NAND gates or only NOR gates.

XNOR gate constructed using only NOR gates

However, XNOR gate can be made with 3 gates (1x OR & 2x NAND gates) as shown

below:

59
Ex-NOR Function Realisation using NAND gates

X-NOR gates are used mainly in electronic circuits that perform arithmetic operations

and data checking such as adders, subtractors, parity checkers, etc. Because Ex-NOR gate

gives an output of logic level “1” whenever its two inputs are equal, it can be used to

compare the magnitude of two binary digits or numbers and so Ex-NOR gates are used in

digital comparator circuits.

60

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy