CMP241PART1&2
CMP241PART1&2
Arithmetic operations using decimal numbers are quite common. However, in logical
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
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
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.
Position 3 2 1 0 -1
Base
The weights for whole numbers are positive powers of ten that inrease from right to left,
For fractional numbers, the weghts are negative powers of ten that decrease from left to
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
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
47 = (4 × 101) + (7 × 100 )
= (4 × 10) + (7 × 1)
= 40 + 7
= 47
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
= (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
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
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
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
DECIMAL
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
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
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.
Solution:
(1001)2 = X10
= 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:
7
Example 2: Convert the fractional binary 0.0110 to decimal
Solution:
(0.0110)2 = X10
= (0.375)10
Solution:
(1011.101)2 = X10
= 8 +0 + 2 + 1 + 0.5 + 0 + 0.125
= (11.625)10
Related questions:
the remainder is written after each division. The remainders are then taken in the reverse
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
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
(0.4375)10= (0.0111)2
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
In the octal number system, each digit correspond to the powers of 8. The weight of each
10
To convert from octal to decimal, multiply each octal digit by its weight and add the
resulting products.
Solution:
(47)8 = X10
47 = 4 x 81 + 7 x 80
=4x8 +7x1
= 32 + 7
= 39
(48)8 = (39)10
Solution:
(22.34)8 = X10
= 16 + 2 + 3 x 1/8 +4 x 1/64
= (18.4375)
(22.34)8 = (18.4375)10
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.
Solution:
(19.11)10 = X8
(19.11)10 = (23.07024)8
Since the base of octal number is 8, i.e., the third power of 2, each octal number is
Solution:
(57)8 = X2
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
(57.127)8 = (101111.001010111)2
The given binary number is grouped into a group of 3 bits, starting at the octal point
Solution:
(1110101101)2 = X8
1 6 5 5
(1110101101)2 = 16558
Solution:
(1101101.11101)2 = X8
1 5 5 . 7 2
13
(1101101.11101)2 = (155.72)8
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
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
15
Solution: Starting from the right we group the digit into group of four (4). Each group of
(100101110)2 = X16
1 2 E
1001011102 = (12E)16
equivalent.
Solution:
(11110101100110110000)2 = X16
F 5 9 B 0
(11110101100110110000)2 = F59B016
number equivalent.
Solution:
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).
16
1 2 E . D 8
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.
Solution:
(5D. 2A)16 = X2
5 D . 2 A
Related question: Convert the hexadecimal number F59B0 to its binary equivalent.
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
Solution:
(2479.859)10 = X16
17
16 x 0.859 = 13.744 => 13 (D)
(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 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.
BINARY ADDITION
The four basic rules for adding binary digits (bits) are as follows:
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
(a) 11 - 01 (b) 11 – 10 (c) 111 – 010 (d) Subtract 011 from 101
Solution:
110 01 101
BINARY MULTIPLICATION
Binary multiplication of two bits is the same as multiplication of the decimal digits 0 and
0×0=0
0×1=0
1×0=0
20
1×1=1
Solution:
× 11 ×101
11 111
+11 000
1001 111
100011
BINARY DIVISION
0÷1=0
1÷1=1
Similar to the decimal system, division by zero is meaningless. Division in binary follows
Solution:
10 11
21
11 10
000 10
10
00
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) 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
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
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
Decimal digit 0 1 2 3 4 5 6 7 8 9
BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
To express any decimal in BCD, simply replace each decimal digit with the appropriate
Solution: (a) 3 5
0011 0101
35 = 00110101
23
(b) 9 8
1001 1000
98 = 10011000
(c) 1 7 0
178 = 000101110000
(d) 2 4 6 9
2469 = 0010100001101001
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
8 6
10000110 = 86
3 5 1
351 = 001101010001
24
(c) 1001 0100 0111 0000
9 4 7 0
9470 = 1001010001110000
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 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
Solution: The decimal number additions are shown for comparison purpose:
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.
Solution: The decimal number additions are shown for comparison purpose:
(a) 1001 9
+ 0100 +4
0001 0011
1 3
(b) 1001 9
+ 1001 +9
0001 1000
1 8
+ 0001 0101
26
+ 0110 Add 6 to invalid code, Add 31
3 1
+ 0101 0011
1 2 0
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
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.
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
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
29
2. Going from left to right, add each adjacent pair of binary code bits to get the next
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
1. The most significant bit (left most) in the binary code is the same as the
2. Add each binary code bit generated to the gray code bit in the next adjacent
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:
1 + 1 + 0 + 0 + 0 + 1 + 1 + 0
1 0 1 0 0 1 0 1
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
Computers, printers and other devices must process both alphabetic and numeric
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
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:
3. Unicode.
ASCII
ASCII is the abbreviation for American Standard Code for Information Interchange.
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
'a' or '@' or an action of some sort. ASCII was developed a long time ago and now the
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.
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
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
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
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.
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
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
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
00101
BCD code
Now let’s assume that an error occurs in the third bit from the left (the 1 becomes a 0)
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
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
(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
Related Question: The following ASCII character is received by an odd parity system:
00110111. Is it correct?
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
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
Number of parity Bits: if the number of data bits is designed d, then the number of
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
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.
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
Step 2. Check the group for proper parity. A 0 represents a good parity check, and 1
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
BIT DESIGNATION P1 P2 D1 P3 D2 D3 D4
BIT POSITION 1 2 3 4 5 6 7
Received code 0 0 1 0 0 0 1
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
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
Result:
The error position code is 0111 (binary seven). This says that the bit in position 7 is in
Related Question: The code 101111001 is received. Correct any error if odd parity is
used.
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
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
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
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
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.
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
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
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
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
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
46
The total number of possible combinations of binary inputs to a gate is determined by the
following formula:
Where N is the number of possible input combinations and n is the number of input
variables. To illustrate,
You can determine the number of input bit combinations for gates with any number of
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
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
A B Y = A+B
0 0 0
0 1 1
1 0 1
1 1 1
The study of the above truth table reveals that the logical OR operation resembles
addition.
Addition in Boolean algebra involves values that are either binary 1 or binary 0. The
48
0+0=0
0+1=1
1+0=1
1+1=1
Note that Boolean addition differs from binary addition in the case where two 1’s are
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 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
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
Y=Ā
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
a letter. The complement of a variable is designed by a bar over the letter. A variable can
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
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
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
A B Y=A.B
0 0 1
0 1 1
1 0 1
52
1 1 0
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
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.
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.
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
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
gives Q = 1
Boolean Expression Q =
A B C
The Exclusive-NOR Gate function or Ex-NOR for short is a digital logic gate that is the
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.
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
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
60