Number Systems & Logic Gates Guide
Number Systems & Logic Gates Guide
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
NUMBER SYSTEM
Based on the base value and the number of allowed digits, number systems are of many types.
The four common types of Number System are:
Binary Number System
Decimal Number System
Octal Number System
Hexadecimal Number System
Number System with base value 2 is termed as Binary number system. It uses 2 digits i.e. 0 and 1
for the creation of numbers. The numbers formed using these two digits are termed Binary
Numbers. The binary number system is very useful in electronic devices and computer systems
because it can be easily performed using just two states ON and OFF i.e. 0 and 1.
Decimal Numbers 0-9 are represented in binary as: 0, 1, 10, 11, 100, 101, 110, 111, 1000, and
1001
For example, 14 can be written as 1110, 19 can be written as 10011, 50 can be written as
110010.
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
2 9 1
2 4 1
2 2 0
2 1 0
2 0 1
advantages
Logic operations are the backbone of any digital computer, although solving a problem on
computer could involve an arithmetic operation too. The introduction of the mathematics of logic
by George Boole laid the foundation for the modern digital computer. He reduced the
mathematics of logic to a binary notation of ‘0’ and ‘1’.
Another advantage of this number system was that all kind of data could be conveniently
represented in terms of 0s and 1s.
Also basic electronic devices used for hardware implementation could be conveniently and
efficiently operated in two distinctly different modes.
HEXADECIMAL 0 1 2 3 4 5 6 7 8 9 A B C D E F
DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Sample Problems
2 19 1
2 9 1
2 4 0
2 2 0
1
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
Collect remainders from bottom to top we will get 10011 which is binary representation of
decimal number 10.
Therefore (19)10 = (10011)2
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Binary Operations:
Binary Addition is a base-2 number system that uses two states 0 and 1 to represent a
number. We can also call it to be a true state and a false state. A binary number is
built the same way as we build a normal decimal number.
Binary arithmetic is an essential part of various digital systems. You can add, subtract,
multiply, and divide binary numbers using various methods. These operations are
much easier than decimal number arithmetic operations because the binary system
has only two digits: 0 and 1.
Binary additions and subtractions are performed as same in decimal additions and
subtractions. When we perform binary additions, there will be two outputs: Sum (S )
and Carry (C).
There are four parts in any division: Dividend, Divisor, quotient, and remainder.
4. There are four parts in any division: Dividend, Divisor, quotient, and remainder.
Binary arithmetic is essential part of all the digital computers and many other digital
system.
Addition Binary Numbers
Rule to follow when binary numbers are added:
0+0=0
0+1=1
1+0=1
1 + 1 = 0 (with a carry of 1)
Examples - Adding Binary and Decimal Numbers
Decimal Binary
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
Decimal Binary
5 101
1 +6 + 110
= 11 = 1011
6 110
2 +6 + 110
= 12 = 1100
15 1111
3 + 20 + 10100
= 35 = 100011
3.25 11.01
4 + 5.75 + 101.11
= 9.00 = 1001.00
0- 0=0
1- 0=1
1- 1=0
0- 1 = 1 (with a borrow of 1)
Examples - Subtracting Binary and Decimal Numbers
Decimal Binary
9 1001
1 -5 - 101
=4 = 0100
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
Decimal Binary
16 10000
2 -3 - 11
= 13 = 01101
6.25 110.01
3 - 4.50 - 100.10
= 1.75 = 001.11
0x0=0
0x1=0
1x0=0
1x1=1
Some binary multiplication examples are given below for a better understanding of this
concept.
Example 1: Solve 1010 × 101
Solution:
1010 × 101
1010
(×) 101
—————–
1010
0000
——————
01010 ……. First Intrmediate Sum
1010
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
——————–
110010-------result
Comparison with Decimal values:
10102 = 1010
10102 = 510
10 x 5 = 5010
(110010) 2 = 5010
0/1=0
1/1=1
GRAY CODE Gray code has a property that two successive numbers differ in only one
bit because of this property gray code does the cycling through various states with minimal
effort and is used in K-maps, error correction, communication, etc.
For example, the sequence of Gray codes for 3-bit numbers is: 000, 001, 011, 010, 110, 111, 101,
100, so G(4)=6.
n-bit Gray Codes can be generated from a list of (n-1)-bit Gray codes using the following
steps.
1. Let the list of (n-1)-bit Gray codes be L1. Create another list L2 which is the reverse of L1.
2. Modify the list L1 by prefixing a ‘0’ in all codes of L1.
3. Modify the list L2 by prefixing a ‘1’ in all codes of L2.
4. Concatenate L1 and L2. The concatenated list is the required list of n-bit Gray codes.
Binary : 01001
Gray : 01101
BINARY TO GRAY CONVERSION :
1. The Most Significant Bit (MSB) of the gray code is always equal to the MSB of the given
binary code.
2. Other bits of the output gray code can be obtained by XORing binary code bit at that index
and previous index.
BCD CODE:
The BCD equivalent of a decimal number is written by replacing each decimal digit in
the integer and fractional parts with its four bit binary equivalent.the BCD code is more
precisely known as 8421 BCD code , with 8,4,2 and 1 representing the weights of
different bits in the four-bit groups, Starting from MSB and proceeding towards LSB.
This feature makes it a weighted code , which means that each bit in the four bit group
representing a given decimal digit has an assigned weight.
Many decimal values, have an infinite place-value representation in binary but have a
finite place-value in binary-coded decimal. For example, 0.2 in binary is .001100…
and in BCD is 0.0010. It avoids fractional errors and is also used in huge financial
calculations.
Consider the following truth table and focus on how are these represented.
Truth Table for Binary Coded Decimal
0 0000
1 0001
2 0010
3 0011
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
EXCESS-3 CODE
The excess-3 code (or XS3) is a non-weighted code used to express code used to
express decimal numbers. It is a self-complementary binary coded decimal (BCD) code
and numerical system which has biased representation. It is particularly significant for
arithmetic operations as it overcomes shortcoming encountered while using 8421 BCD
code to add two decimal digits whose sum exceeds 9. Excess-3 arithmetic uses
different algorithm than normal non-biased BCD or binary positional number system.
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
The codes 0000 and 1111 are not used for any digit.
Example −Convert decimal number 23 to Excess-3 code.
So, according to excess-3 code we need to add 3 to both digit in the decimal number
then convert into 4-bit binary number for result of each digit. Therefore,
= 23+33=56 =0101 0110 which is required excess-3 code for given decimal number 23.
Example −Convert decimal number 15.46 into Excess-3 code.
According to excess-3 code we need to add 3 to both digit in the decimal number then
convert into 4-bit binary number for result of each digit. Therefore,
= 15.46+33.33=48.79 =0100 1000.0111 1001 which is required excess-3 code for
given decimal number 15.46.
Converting into Binary Coded Decimal (BCD) codes
One should note that to given Excess-3 code, the equivalent decimal number can be
determined by splitting number into 4-bit group starting from least significant for integer
part and from leftmost digit for fractional part. Then subtract 0011 (=3) from each f our-
bit group that will be binary decimal digit (BCD) form of that number. Now you can also
convert this BCD code into decimal number by converting each 4-bit group into decimal
digit.
Example − Convert Excess-3 code 1001001 into BCD and decimal number.
So, grouping 4-bit for each group, i.e., 0100 1001 and subtract 0011 0011 from given
number. Therefore,
= 0100 1001 -0011 0011 =0001 0110
So, binary coded decimal number is 0001 0110 and decimal number will be 16.
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
Self-complementary property
Excess-3 code is non-weighted and self complementary code. A self
complementary binary codes are always compliment themselves. The complement of a
binary number can be obtained from that number by replacing 0’s with 1’s and 1’s with
0’s. The sum of binary number and its complement is always equal to decimal 9. In
other words, the 1’s complement of an excess-3 code is the excess-3 code for the
9’s complement of the corresponding decimal number.
For example, the excess-3 code for decimal number 5 is 1000 and 1’s complement of
1000 is 0111, which is excess-3 code for decimal number 4, and it is 9’s complement of
number 5.
For example, the ASCII encoding for the lowercase letter "m" is represented in the following
ways:
ASCII characters were initially encoded into 7 bits and stored as 8-bit characters with the most
significant bit -- usually, the left-most bit -- set to 0.
ASCII was the first major character encoding standard for data processing. Most modern
computer systems use Unicode, also known as the Unicode Worldwide Character Standard. It's a
character encoding standard that includes ASCII encodings.
The Internet Engineering Task Force (IETF) adopted ASCII as a standard for internet data when
it published "ASCII format for Network Interchange" as RFC 20 in 1969. That request for
comments (RFC) document standardized the use of ASCII for internet data and was accepted as
a full standard in 2015.
ASCII encoding is technically obsolete, having been replaced by Unicode. Yet, ASCII characters
use the same encoding as the first 128 characters of the Unicode Transformation Format 8, so
ASCII text is compatible with UTF-8.
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
PARITY CODE
The parity code is used for the purpose of detecting errors during the transmission of
binary information. The parity code is a bit that is included with the binary data to be
transmitted.
The inclusion of a parity bit will make the number of 1’s either odd or even. Based on the
number of 1’s in the transmitted data, the parity code is of two types.
In even parity, the added parity bit will make the total number of 1’s an even number. If
the added parity bit make the total number of 1’s as odd number, such parity code is said
to be odd parity code.
Let us consider the 4-bit message(1011) to be transmitted. Adding 1 to the message will
make the total number of 1’s in the message to be an even number. Hence it is called as
even parity.
For the same message, adding 0 with the transmitted message will make the total
number of 1’s to be an odd number. Hence it is called as odd parity. It is shown in the
example below.
000 111
001 110
010 101
011 100
100 011
101 010
110 001
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
111 000
Lets see arithmetic operations: Subtractions and Additions in 1’s complement binary numbers.
Subtractions by 1’s Complement:
The algorithm to subtract two binary number using 1’s complement is explained as following
below:
When positive number has greater magnitude, then take simply 1’s complement of negative
number and the end-around carry of the sum is added to the least significant bit (LSB).
Example: Add 1110 and -1101.
So, take 1’s complement of 1101, which will be 0010, then add with given number.
So, 1110+0010=1 0000 , then add this carry bit to the LSB, 0000+1=0001 , which is the
answer.
Note that if the register size is big then fill the same value of MSB to preserve sign magnitude
for inputs and output.
Case-2: Addition of positive and negative number when negative number has greater
magnitude:
When the negative number has greater magnitude, then take 1’s complement of negative number
and add with given positive number. Since there will not be any end-around carry bit, so take 1’s
complement of the result and this result will be negative.
Example: Add 1010 and -1100 in five-bit registers.
Note that there are five-bit registers, so these new numbers will be 01010 and -01100.Now take
1’s complement of 01100 which will be 10011 and add 01010+10011=11101 . Then take 1’s
complement of this result, which will be 00010 and this will be negative number, i.e., -00010,
which is the answer.
Case-3: Addition of two negative numbers:
You need to take 1’s complement for both numbers, then add these 1’s complement of numbers.
Since there will always be end-around carry bit, so add this again to the MSB of result. Now,
take 1’s complement also of previous result, so this will be negative number.
Alternatively, you can add both negative number directly, and get this result which will be
negative only.
Example: add -1010 and -0101 in five bit-register.
These five bit numbers are -01010 and -00101. Add complements of these numbers,
10101+11010 =1 01111 . Since, there is a carry bit 1, so add this to the LSB of result, i.e.,
01111+1=10000 . Now take the 1’s complement of this result, which will be 01111 and this
number is negative, i.e, -01111, which is answer.
Note that end-around-carry-bit addition occurs only in 1’s complement arithmetic operations
but not in 2’s complement arithmetic operations.
TWO’S COMPLEMENT 2’s complement of binary number is 1’s complement of given number
plus 1 to the least significant bit (LSB). For example 2’s complement of binary number 10010 is
(01101) + 1 = 01110.
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
Lets see arithmetic operations: Subtractions and Additions in 2’s complement binary numbers.
When the negative number has greater magnitude, then take 2’s complement of negative number
and add with given positive number. Since there will not be any end-around carry bit, so take 2’s
complement of the result and this result will be negative.
Example −Add 1010 and -1100 in five-bit registers.
Note that there are five-bit registers, so these new numbers will have 01010 and -01100. Now
take 2’s complement of 01100 which will be 10100 and add 01010+10100=11110. Then take
2’s complement of this result, which will be 00010 and this will be negative number, i.e., -
00010, which is the answer.
Case-3 − Addition of two negative numbers −
You need to take 2’s complement for both numbers, then add these 2’s complement of numbers.
Since there will always be end-around carry bit, so it is dropped. Now, take 2’s complement also
of previous result, so this will be negative number.
Alternatively, you can add both of these Binary numbers and take result which will be negative
only.
Example − add -1010 and -0101 in five bit-register.
These five bit numbers are -01010 and -00101. Add 2’s complements of these numbers,
10110+11011 =1 10001. Since, there is a carry bit 1, so it is dropped. Now take the 2’s
complement of this result, which will be 01111 and this number is negative, i.e, -01111, which
is answer.
Note that 2’s complement arithmetic operations are much easier than 1’s complement because of
there is no addition of end-around-carry-bit.
The addition of BCD numbers is slightly different from binary addition. Here, the rules
of binary addition are partially applicable only to the individual 4-bit groups. The BCD
addition, is thus carried out by individually adding the corresponding 4-bit groups
starting from the LSB side and if there is a carry to the next group, or if the result
belongs to any of the 6 illegal states than we add 610(0110) to the sum term of that
group and resulting carry is added in the next group.
When we add 6 and 7 in BCD, we get 1101 which is an invalid state therefore, we
add 0110 (6) to the sum to get correct result which is 0001 0011 (13).
wex
BCD representation of 8765 is given as 1000 0111 0110 0011 and for 3943 it is 0011
1001 0100 0011.
LOGIC GATE
A logic gate is an idealized or physical device implementing a Boolean function, that take inputs
and produces a single logic output.
Computers are made up of logic gates. Logic gates take information coming in and output
different information depending on what type of gate they are.
Truth Table
A truth table is a representation of all possible combinations of Input values and their result in a
tabular format. If the result of a logical expression of logical statement is always true or 1, it is
known as Tautology. If the result expression or logical statement is always false or 0, it is known
as Fallacy.
A B C Decimal Equivalent
0 0 0 0
0 0 1 1
0 1 0 2
0 1 1 3
1 0 0 4
1 0 1 5
1 1 0 6
1 0 1 7
The number of rows in a truth table is calculated as 2 n where n is the total number of variables.
Therefore if there are three variables A, B and C, then the possible values will be 23 = 8
combinations. It can be represented a follows:
Thus, for n variable, the number of possible combinations of inputs will be 2 n, which are binary
representations of the Integer from 0 to (2 n-1).
X X'
0 1
1 0
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
ii) AND (Conjunction) Operator: This operator operates on two or more operands on
two or more operands. AND operator is used to perform logical multiplication and the
symbol for AND operator is dot (' . ').
X X' F
0 0 0
0 1 0
1 0 0
1 1 1
X X' F
0 0 0
0 1 0
1 0 0
1 1 1
iv)NAND
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
v)NOR
vi)EX-OR
vii)EX-NOR
Logic Gates
A gate is a circuit which takes one or more inputs and generate only one output. A gate is a
digital circuit because it can take only two values, i.e. either high or low. Logic gates use the
binary operators AND, OR and NOT There are three fundamental logic gates which are as
follows:
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
AND Gate
AND Gate works on two or more inputs which result in a single output. When all the inputs are 1
or high, then the output is 1 otherwise the output is 0.
OR Gate
OR Gate works on two or more inputs which result in a single output. When any of the input
signals is 1, the output signal is 1 and if all input signal is 0, the output signal will be 0.
NOT Gate
NOT gate works on a single input signal and generates a single output signal. The output state is
a negation or complement of an input signal which is denoted by (') NAND Gate, Logic NOT
NAND Gate
This gate is the combination of AND or NOT gate. The NAND gate has two or more input but
only one output. It produces output 1 when any of the input is 0.
NOR Gate
The NOR gate (negated OR) gives an output of 1 only if both inputs are 0, it gives 0
otherwise. For n-input gate if all inputs are 0 then it gives 1 otherwise 0.
XOR Gate– The XOR gate gives an output of 1 if either both inputs are different, it
gives 0 if they are same. For n-input gate if the number of input 1 are odd then it gives
1 otherwise 0.
XNOR Gate The XNOR gate (negated XOR) gives an output of 1 if both inputs are
same and 0 if they are different. For n-input gate if the number of input 1 are even
then it gives 1 otherwise odd.
Universal Logic Gates – Out of the eight logic gates discussed above, NAND and
NOR are also known as universal gates since they can be used to implement any
digital circuit without using any other gate. This means that every gate can be created
by NAND or NOR gates only. Implementation of three basic gates using NAND and
NOR gates is shown below –
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
Hamming code is a set of error-correction codes that can be used to detect and correct
the errors that can occur when the data is moved or stored from the sender to the
receiver.
Redundant bits – Redundant bits are extra binary bits that are generated and added to
the information-carrying bits of data transfer to ensure that no bits were lost during the
data transfer. The number of redundant bits can be calculated using the following
formula:
2^r ≥ m + r + 1
where, r = redundant bit, m = data bit
Suppose the number of data bits is 7, then the number of redundant bits can be calculated
using: = 2^4 ≥ 7 + 4 + 1 Thus, the number of redundant bits= 4
Parity bits. A parity bit is a bit appended to a data of binary bits to ensure that the total
number of 1’s in the data is even or odd. Parity bits are used for error detection. There are
two types of parity bits:
1. Even parity bit: In the case of even parity, for a given set of bits, the number of 1’s
are counted. If that count is odd, the parity bit value is set to 1, making the total count
of occurrences of 1’s an even number. If the total number of 1’s in a given set of bits
is already even, the parity bit’s value is 0.
2. Odd Parity bit – In the case of odd parity, for a given set of bits, the number of 1’s
are counted. If that count is even, the parity bit value is set to 1, making the total
count of occurrences of 1’s an odd number. If the total number of 1’s in a given set of
bits is already odd, the parity bit’s value is 0.
Algorithm of Hamming code: Hamming Code is simply the use of extra parity bits to
allow the identification of an error.
1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
3. All the other bit positions are marked as data bits.
4. Each data bit is included in a unique set of parity bits, as determined its bit position in
binary form.
a. Parity bit 1 covers all the bits positions whose binary representation
includes a 1 in the least significant position (1, 3, 5, 7, 9, 11, etc).
b. Parity bit 2 covers all the bits positions whose binary representation
includes a 1 in the second position from the least significant bit (2, 3, 6, 7,
10, 11, etc).
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
c. Parity bit 4 covers all the bits positions whose binary representation
includes a 1 in the third position from the least significant bit (4–7, 12–15,
20–23, etc).
d. Parity bit 8 covers all the bits positions whose binary representation
includes a 1 in the fourth position from the least significant bit bits (8–15,
24–31, 40–47, etc).
e. In general, each parity bit covers all bits where the bitwise AND of the
parity position and the bit position is non-zero.
5. Since we check for even parity set a parity bit to 1 if the total number of ones in the
positions it checks is odd.
6. Set a parity bit to 0 if the total number of ones in the positions it checks is even.
Determining the position of redundant bits – These redundancy bits are placed at
positions that correspond to the power of 2.
As in the above example:
The number of data bits = 7
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
Suppose the data to be transmitted is 1011001, the bits will be placed as follows:
To find the redundant bit R1, we check for even parity. Since the total number of 1’s
in all the bit positions corresponding to R1 is an even number the value of R1 (parity
bit’s value) = 0
R2 bit is calculated using parity check at all the bits positions whose binary
representation includes a 1 in the second position from the least significant bit. R2:
bits 2,3,6,7,10,11
To find the redundant bit R2, we check for even parity. Since the total number of 1’s
in all the bit positions corresponding to R2 is odd the value of R2(parity bit’s
value)=1
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
R4 bit is calculated using parity check at all the bits positions whose binary
representation includes a 1 in the third position from the least significant bit. R4: bits
4, 5, 6, 7
1. To find the redundant bit R4, we check for even parity. Since the total number of 1’s
in all the bit positions corresponding to R4 is odd the value of R4(parity bit’s value) =
1
2. R8 bit is calculated using parity check at all the bits positions whose binary
representation includes a 1 in the fourth position from the least significant bit. R8: bit
8,9,10,11
SYLLABUS Unit 1: Introduction to Number System and Logic Gates: Number Systems- Binary,
Decimal, Octal, Hexadecimal; Codes- Grey, BCD,Excess-3, ASCII, Parity; Binary Arithmetic- Addition,
Subtraction, Multiplication, Division using Sign Magnitude,1’s compliment, 2’s compliment, BCD
Arithmetic; Logic Gates-AND, OR, NOT, NAND, NOR, EX-OR, EX-NOR.
To find the redundant bit R8, we check for even parity. Since the total number of 1’s
in all the bit positions corresponding to R8 is an even number the value of R8(parity
bit’s value)=0. Thus, the data transferred is:
Error detection and correction: Suppose in the above example the 6th bit is changed
from 0 to 1 during data transmission, then it gives new parity values in the binary
number:
For all the parity bits we will check the number of 1’s in their respective bit positions.
For R1: bits 1, 3, 5, 7, 9, 11. We can see that the number of 1’s in these bit positions are 4
and that’s even so we get a 0 for this.
For R2: bits 2,3,6,7,10,11 . We can see that the number of 1’s in these bit positions are 5
and that’s odd so we get a 1 for this.
For R4: bits 4, 5, 6, 7 . We can see that the number of 1’s in these bit positions are 3 and
that’s odd so we get a 1 for this.
For R8: bit 8,9,10,11 . We can see that the number of 1’s in these bit positions are 2 and
that’s even so we get a 0 for this.
The bits give the binary number 0110 whose decimal representation is 6. Thus, bit 6
contains an error. To correct the error the 6th bit is changed from 1 to 0.