You are on page 1of 65

Digital Systems

• Digital Systems play a very prominent role in our everyday life. These systems have permeated across all aspects of our present
day life related to education, communications, professional, scientific, space, defense, security, medical and weather
monitoring activities etc. This is why we call present age as digital age.

• All digital devices require graphical user interfaces (GUIs) for providing interactive experience to the users.

• Through the GUI interface, users feed commands to the digital devices to change their operational behavior.

• These digital devices have special‐purpose digital computer embedded within them. This embedded digital computer may have a
limited or highly advanced processing capability depending upon the type of requirement.

• To follow a sequence of instructions, these devices are provided with a set of instructions called a program and a set of data for
operation. The users can specify and change the program or the data according to their specific needs.

• Because of this flexibility, general‐purpose digital computers can perform a variety of information‐processing tasks for a wide
spectrum of applications.
• Since most of these computers (analog or digital) have to process physical quantities such as temperature, pressure, light intensity,
humidity and many other parameters, the relevant data has to be presented in a form that the computer can understand.

• Analog computers handle physical parameters that vary


continuously and digital computers handle data that have
discrete values.
Digital Systems
• There are two basic ways of representing the numerical values of physical quantities.
• Analog Representation
• Digital Representation
Analogue: Numerical values are expressed as continuous range of values
between the two expected extreme values.
Example:
- Temperature of an oven from 0 to 100 °C or
- Voltage in an electronic circuit from 6.5 V or 6.49 V to 12V.
Underlying concept of analogue representation is that variation in
the numerical value is
 continuous in nature and
 has theoretically infinite possible values between the two extremes.
Digital: Numerical values of a quantity are
represented in step of discrete values using
binary numbers. For example, the temperature
of the oven may be represented in steps of 1 °C
as 64 °C, 65 °C, 66 °C and so on.

An analogue representation gives a continuous


output, a digital representation produces a
discrete output.
Advantages of Digital Systems
Digital systems are simpler to design, have higher accuracy, noise immunity, programmability, easier storage of data and ease
of fabrication in integrated circuit form.
Physical quantities such as position, velocity, acceleration, force, pressure, temperature and flow rate etc are analogue in nature.
Analogue variables representing physical quantities are digitized at the input of digital systems for ease of processing.
In a typical digital system dealing with analogue inputs and outputs, analogue variables are digitized at the input using
analogue-to-digital converter and reconverted back to analogue form at the output using a digital-to-analogue converter.
Once the input physical quantities are digitized, they need to be represented using some number system for ease of processing
by the digital systems and for drawing meaningful conclusion after processing. This is why we need Number System to
represent data/physical parameters.
Characteristics of a Number System are:
Number of independent digits used.
Place values of the different digits constituting the number
Maximum numbers that can be written with the given number of digits.
The most fundamental characteristic of a Number System is the number of independent digits or symbols used in the number system.
This is known as the radix or base of the number system.
Introduction to Number Systems Decimal system
It is a technique to represent numbers. A number system has
What is a Number System? certain number of symbols available to represent the natural 0 10 20 30 40….…90 100
numbers. Number of such unique symbols is called Radix or
Base of the Number System. 1 11 21 31
Radix determines the place values of different digits 2 12 22 32
in the integer part of the number: place values are given by r 0, r 1, r 2, r 3 and so on,
starting with the digit adjacent to the radix point. 3 13 23 33
in the fractional part of the number: place values are given by r −1, r −2, r −3 and so 4 14 24 34
on, starting with the digit next to the radix point.
Maximum numbers that can be written with 'n' digits in a given number system =r n. 5 15 25 35
Number Systems  Decimal Number System has 10 different symbols 0, 6 16 26 36
1, 2, 3, 4, 5, 6, 7, 8 and 9 and thus its Radix = 10.
 Binary Number System has 2 different symbols 0 & 1 7 17 27 37
and thus its Radix = 2. 8 18 28 38
 Octal Number System has 8 different symbols 0, 1, 2,
3, 4, 5, 6 and 7. Thus its Radix = 8. 9 19 29 39 49…..…99 109
 Hexadecimal Number System has 16 different symbols 0 to
9 and A to F. Thus its Radix = 16. Decimal Number System : All higher numbers after ‗9‘ are obtained

in terms of these 10 digits only.


 Process of writing higher-order numbers after ‗9‘ involves writing the most
significant digit first, followed by writing the lower order digits, one by one,
to obtain the next 10 numbers from ‗10‘ to ‗19‘. The process continues until
all two digit combinations up to ‗99‘ are exhausted. After that three-digit
combinations are started and the process goes on.
 Decimal Number System: Place values of different digits of a mixed decimal number, starting from the decimal point, are
100, 101, 102 and so on (for the integer part) and 10−1, 10−2, 10−3 and so on (for the fractional part).
 Value of a decimal number is expressed as the sum of the various digits multiplied by their place values.
 Example: Decimal number 3586.265
3586 as the integer part which is expressed as and the fractional part expressed as
3586 = 3×103 + 5×102 + 8×101 + 6×100
= 3000 + 500 + 80 +6
265 = 2×10−1 + 6×10−2 + 5×10−3
= 0.2 + 0.06 + 0.005
0 10 20
= 3586 = 0.265
 Octal number system has a radix of 8 with eight distinct digits. 1 11 21
The independent digits are 0, 1, 2, 3, 4, 5, 6 and 7.

 The next 10 numbers that follow ‗7‘, are 10, 11, 12, 13, 14, 15, 16, 17, 20 and 21.
2 12 22
 All higher-order numbers are expressed as a combination of these on the same pattern as the
one followed in the case of the binary and decimal number systems.
3 13 23
 If we omit all the numbers containing the digits 8 or 9, or both, from the decimal number
system, we end up with an octal number system.
4 14 24
Place values for the different digits in the octal number system are 80, 81, 82 and so on (for the

integer part) and 8−1, 8−2, 8−3 and so on (for the fractional part).
5 15 25
8n......82 81 80 . 8-1 8-2 8-3......8-m
6 16 26
7 17 27
Binary Number System
 Binary Number System has a radix of „2‟ with ‗0‘ and ‗1‘ being the two symbols for two numbers.
 All larger binary numbers are represented in terms of ‗0‘ and ‗1‘.
 Process of writing higher order binary numbers after ‗1‘ is similar to the decimal number system. The first 16
numbers in the binary number system are shown here.
 Maximum 16 (= 24) numbers can be written with four digits/bits.
 Starting from the binary point, the place values of different digits in a mixed binary number are 20, 21, 22 and
so on (for the integer part) and 2−1, 2−2, 2−3 and so on (for the fractional part).

2 n......2 2 2 1 2 0 . 2 -1 2 -2 2 -3......2 -m
0 10 100 1000
1 11 101 1001
110 1010
111 1011
1100
1101
1110
1111
Hexadecimal Number System
0 10 20
 Hexadecimal number system is a radix-16 number system and its 16 basic digits are 0, 1, 2, 3,
1 11 21
4, 5, 6, 7, 8, 9, A, B, C, D, E and F.
2 12 22
 Place values of different digits in a mixed hexadecimal number are 160, 161, 162 and so on (for
the integer part) and 16−1, 16−2, 16−3 and so on (for the fractional part).
3 13 23
4 14 24
16n......162 161 160 . 16-1 16-2 16-3......16-m
5 15 25
 The decimal equivalent of A, B, C, D, E and F are 10, 11, 12, 13, 14 and 15 respectively.
6 16 26
 Advantage of a Hexadecimal System over Binary System: 7 17 27
 The hexadecimal number system provides a condensed way of representing 8 18 28
large binary numbers.
9 19 29
 Since, decimal number system is not used in computers and the binary notation
A 1A 2A
appears too cumbersome and inconvenient to handle, hexadecimal representation
provides a simplified method for representing numbers. B 1B 2B
C 1C 2C
D 1D 2D
E 1E 2E
F 1F 2F
Number Base Conversion
Binary to Decimal Conversion Octal-to-Decimal Conversion
Decimal equivalent Sum of all the digits Obtain Decimal equivalent of the octal number (137.21)8
of a = multiplied by
Integer part = 137
given binary number their respective place values.
Decimal equivalent = 1 × 82 + 3 × 81 + 7 × 80
 Integer and fractional parts of the given number are treated = 64 + 24 + 7 = 95
separately. Fractional part = .21
Decimal equivalent = 2 × 8−1 + 1 × 8−2
Binary-to-decimal: = 0.25 + 0.015
= 0.265
Decimal equivalent of (1001.0101)2 is :
Decimal equivalent of (137.21)8 = (95.265)10
Integer part = 1 0 0 1
Equivalent = 1×23 + 0×22 + 0×21 + 1×20 = 8 + 0 + 0 + 1 = 9 Hexadecimal-to-Decimal Conversion
Fractional part = .0101 Obtain Decimal equivalent of a hexadecimal number (1E0.2A)16 :
Equivalent −1 −2
= 0×2 + 1×2 + 0×2 + 1×2 −3 −4
Integer part = 1E0
Therefore, the decimal equivalent of (1001.0101)2 = 9.3125 Decimal equivalent = 1 × 162 + 14 × 161 + 0 × 160
= 256 + 224 + 0 = 480
Fractional part = 2A
Decimal equivalent = 2 × 16−1 + 10 × 16−2
= 0.125 + 0.039 =0.164

Finally decimal equivalent of (1E0.2A)16 = (480.164)10


Decimal to Binary Conversion
Double-Dabble Method: Integer and fractional parts are done separately.
For Integer part: Binary equivalent is found by successive division by 2 and recording the remainders until the
quotient becomes ‗0‘.
 Remainders are written in reverse order to form the binary equivalent.
For Fractional part: Fractional part of the decimal number is multiplied successively by 2 and the carry is
recorded until the result of multiplication is ‗0‘.
 Carry Sequence is written in forward order to form the binary equivalent of the fractional part of the

decimal number.
 If the result of multiplication does not appear to be heading towards zero for the fractional part,
multiplication process is terminated when requisite number of bits have been obtained.
Decimal to Binary Conversion
Example: Finding the binary equivalent of (13.375)10. • Fractional part = .375
 Divide the integer part successively by 2:-  0.375 × 2 = 0.75 with a carry of 0
2 13  0.75 × 2 = 0.5 with a carry of 1 01 1
2 6 — 1 LSD
 0.5 ×2=0 with a carry of 1
2 3 — 0
1101
2 1 — 1  Binary equivalent of fractional part (0.375)10 = (.011)2
0 — 1 MSD
MSD: Most significant digit
LSD: Least significant digit

• Binary equivalent of (13)10 is therefore (1101)2 • Hence, binary equivalent of (13.375)10 = (1101.011)2
Decimal-to-Octal Conversion
• Decimal-to-octal conversion is similar to that of decimal-to-binary conversion.
• Progressive division for integer part and progressive multiplication for fractional part is done by „8‟ (radix).
• Integer and fractional parts of the decimal number are treated separately.
Example: Finding the octal equivalent of (73.75)10
Divide the Integer part = 73 successively by 8 Successive multiplication of Fractional part = 0.75 by 8
8 73 0.75 × 8 = 0 with a carry of 6
8 9 — 1 Octal equivalent of (0.75)10 = (.6)8
8 1 — 1 111

0 — 1

Octal equivalent of (73)10 = (111)8 Therefore, the octal equivalent of (73.75)10 = (111.6)8
Decimal-to-Hexadecimal Conversion Binary–Octal and Octal–Binary Conversions
Decimal-to-hexadecimal conversion process also follows Binary to Octal conversion is done by splitting the integer and
progressive division and multiplication using radix 16. fractional parts into groups of three bits, starting from binary point on
Example: Hexadecimal equivalent of (82.25)10 both sides. Zeros are added to complete the outside groups.
Example: Finding octal equivalent of (1110100.0100111)2
Divide the integer 82 part by 16 successively:
Make Groups of 3 bits = ( 1 110 100 . 010 011 1 )2
16 82
Add zeros as required =(001 110 100 . 010 011 100 )2
16 5 — 2 Write Octal Eq. for each group = (164.234)8
0 — 5

Hexadecimal equivalent of (82)10 = (52)16 Octal to Binary conversion is done by replacing each octal
digit with its three-bit binary equivalent.
 Successive multiplication of Fractional part = 0.25 by 16
Example: Finding binary equivalent of (374.26)8
0.25 × 16 = 0 with a carry of 4 • Given octal number = (374.26)8
Hexadecimal equivalent of (82.25)10 = (52.4)16
 • Binary equivalent = (011 111 100.010 110)2
• Any 0s on the extreme left of the integer part and extreme
right of the fractional part of the equivalent binary number are
omitted.
• Therefore, (011111100.010110)2 = (11111100.01011)2
Binary–Hex Conversions Hex–Binary Conversions
Binary to hex conversion is done by splitting the integer Hex to Binary conversion is done by replacing each hex
and fractional parts into groups of four bits, starting from digit with its four-bit binary equivalent.
the binary point on both sides. Zeros are added to complete Example: Finding the binary equivalent of (1 7 E . F 6)16
the outside groups as required.
• Write Binary equivalent of each hex digit of (1 7 E . F 6)16
Example: Finding the hex equivalent of (0001 0111 1110 . 1111 0110)2
(1011001110.011011101)2. (1 7 E . F 6)16
Make groups of 4 bits from binary point = • Omit Zeros from extreme left of the integer part and extreme
10 1100 1110 . 0110 1110 1 right of the fractional to get the final result.
(000101111110 . 11110110)2
Add Zeros on outside groups =
0010 1100 1110 . 0110 1110 1000 = (101111110.1111011)2
2 C E . 6 E 8
= (2CE.6E8)16
Hex–Octal Conversions Octal–Hex Conversions

For Hex–Octal conversion, given hex number is firstly For Octal–Hex conversion, the octal number is converted to
converted to its binary equivalent, which is further converted binary and then the binary number is transformed in its hex
into its octal equivalent. Hex  Binary  Octal equivalent. Octal  Binary  Hex

Example Finding the octal equivalent of (2F.C4)16 Example Finding the hex equivalent of (762.013)8
Binary equivalent of each hex digit = Write binary equivalent =
(0010 1111.1100 0100)2 (111 110 010.000 001 011)2

Make groups of three digits from binary point = Make groups of 4 bits from binary point=
( 000 101 111 . 110 001 000)2 (1 1111 0010 . 0000 0101 1)2
Add zeros as required=
Write Octal equivalent for each group.= (057.610)8. ( 0001 1111 0010 . 0000 0101 1000)2
Omit zeros from extreme left of integer part and extreme right Write hex equivalent for each group = (1F2.058)16.
of fractional part =
(57.61)8
Compliments of Numbers Diminished Radix Complement
 Complements are used in digital computers to • Take a n digit number N with base r, then (r - 1)‘s
complement of N is known as diminished radix
 Simplify the subtraction operation complement and this is given as = (r n - 1) - N
 Carrying out Logical manipulation.  For Decimal Numbers:
Radix r = 10 and (r – 1) = 9 then
 Simplifying operations leads to simpler, less
then 9‘s complement of N = (10 n - 1) - N
expensive circuits to implement the operations.
 10 n represents a number with single 1 followed by ‗n‟ 0‘s.
 There are two types of complements for each 10 n - 1 represents a number with ‗n‟ 9‘s.
base‐r system:
 For example, if n = 4 (n is number of digits):
 Radix Complement - referred to as the r‟s  104 = 10,000 and
complement  104 - 1 = 9999.
 Diminished Radix complement - referred to as • Hence, 9‟s complement of a decimal number is obtained by
the (r - 1)‟s complement subtracting each digit from 9.
• The 9‘s complement of 546700  999999 - 546700 = 453299
• The 9‘s complement of 012398  999999 - 012398 = 987601
Diminished Radix Complement
• For Binary Numbers:
 Radix r = 2 and r - 1 = 1, so the 1‘s complement of N = (2n - 1) – N
 2n represents a binary number with 1 followed by ‗n‟ number of 0‘s.
 2n – 1 represents a binary number with ‗n‟ number of 1‘s.
• For example, if n = 4  24 = 16 = (10000)2 and
• 24 - 1 = (1111)2. Thus, the 1‘s complement of a binary number is obtained by
subtracting each digit from 1.
• Since subtracting a binary bit ‗1‘ or ‗0‘ from ‗1‘, always yields the
opposite binary number, the 1‘s complement of a binary number is
formed by changing 1‘s to 0‘s and 0‘s to 1‘s.
• Examples:
• 1‘s complement of 1011000 is 0100111.
• 1‘s complement of 0101101 is 1010010.
• Similarly, (r - 1)‟s complement of octal is obtained by subtracting each digit from „7‟ and for
hexadecimal numbers, it is obtained by subtracting each digit from „F‟ (decimal 15).
Octal System 82  1 0 0  1 X 82 + 0 X 80 + 0 X 80 = 64 Comp of N in Octal System (82 - 1) - N  77 - N
Decimal System 102  1 0 0  1 X102 + 0 X100 + 0 X 100 = 100 Comp of N in Decimal System (102 - 1) - N  99 - N
Hex System 162  1 0 0  1 X162 + 0 X160 + 0 X 160 = 256 Comp of N in Hex System (162 - 1) - N  FF - N
Radix (r‘s) Compliment 'r' is Radix (r-1) Complement 'r ' Complement
Binary Number System: The r‟s complement of a binary
number is called 2‘s complement.
2‟s complement is obtained by adding ‗1‘ to 1‘s complement.
Example: For 2‘s complement of (1010)2 , Take 1‘s
complement of (1010)2 and Add ‗1‘ 0101 + 1 = 0110
Decimal Number System: 10‟s complement is obtained by
adding ‗1‘ to the 9‘s complement.
Example: For 10‘s complement of (2496)10 , Take 9‘s
complement and Add ‗1‘  7503+1 = (7504)10.
Octal Number System: 8‟s complement is obtained by
adding ‗1‘ to the 7‘s complement.
Example: For 8‘s complement of (562)8 , Take 7‘s
complement and Add ‗1‖  215 +1 = is (216)8
Hexadecimal Number System: 16‟s complement is Note: Diminished Complement is (r-1)‟s Complement,
obtained by adding ‗1‘ to the 15‘s complement. Radix Compliment is r„s Complement
If the original number 'N' contains a radix point, the
Example: For 16‘s complement of (2AE)16 , Take 15‘s
point is removed temporarily to form the r's or (r-1)'s
complement and Add ‗1‘ = D51 + 1 =(D52)16.
complement. Thereafter, radix point is then restored to
the complemented number in the same relative position.
Complement of the complement restores the number to its
original value.
Number Representation in Binary Unsigned Binary Number Representation

 Unsigned Number Representation Standard binary encoding is followed


Only positive values are represented. There are no
 Signed Number Representation negative numbers.
Range: for n bits range of numbers is 0 to 2n - 1
 1‘s Complement Representation
Example: Representation of first 16 decimal
 2‘s Complement Representation numbers from 0 to 15 requires 4-bit binary numbers.
Range of 4 bit-binary representation is given as
: 0 to 24 - 1 i.e. 0 to 15 (total 16 numbers)

Binary Decimal Binary Decimal


0000 0 1000 8
0001 1 1001 9
0010 2 1010 10
0011 3 1011 11
0100 4 1100 12
0101 5 1101 13
0110 6 1110 14
0111 7 1111 15
Subtraction of Unsigned Numbers with r's Complement Method
• To subtract two 'n' bit unsigned numbers A & B with radix „r‟, take following steps. (When A – B is to be solved
– A is called Minuend and B is called Subtrahend)
Step-1: Add Minuend A to r's complement of the subtrahend B.
A + (r n - B) = A - B + r n (Ex: 66 – 36 + 102 = 130)
Step-2:if A ≥ B, then end carry produced by above result will have to be discarded, and rest will be A - B.
Step-3: If Step-2 check fails i.e. A < B (or we can say B > A), in that case
 result at Step-1 will not produce an end carry, then result will be equal to r n - (A - B), which is the
r's complement of (A - B). For Example: If A= 36 and B= 66
rn – (A – B)  102 –(36 - 66)  [102 – (-30)]
 To obtain the final result, take r's complement of the sum and place a negative sign in front.
• If the two numbers do not have equal number of digits, then precede the shorter number with number
of zeros to make the number of bits equal.
Example of Subtraction of Example of Subtraction of
Unsigned Decimal Numbers using Complement Unsigned Binary Numbers using Complement
Example 1: Using 10's complement, subtract (82357 – Example-3: Given the two binary numbers P = 1010100 and
5670)10. (Where A is minuend and B is Subtrahend) Q = 1000011, perform the subtraction
9‘s complement of B = 99999 – 05670 = 94329 (a) P - Q and (b) Q - P by using 2‟s complements.
10‘s complement of B = 94329 + 1 = 94330 (a) P - Q  P = 101 0100 Minuend is Greater.
A = 82357 2‘s complement of Q = 011 1101
10's complement of B = 94330 Sum = 1 001 0001
Add 1 76687 ; there is '1' as end carry Discard end carry 27= - 1 000 0000 - Subtract from ―Sum‖
Since A ≥ B, for final result discard carry : 76687 Answer: P - Q = 0010001
Example 2: Subtract (5670 – 82357)10 (b) Q - P  Q = 1000011 Here Minuend is smaller
9‘s complement of B = 99999 – 82357 = 17642 2‘s complement of P = + 0101100
10‘s complement of A = 17642 + 1 = 17643 Sum= 1101111 There is no end carry.
A = 05670 Therefore, the answer of Q - P = – (2‘s complement of
10's Complement of B = 17643
1101111)
Add 23313 ; Since A < B, no end carry = – 0010001
Take 10's complement of 23313 & prefix minus sign to get final
result: - 76687
Subtraction Using (r-1)‘s Complement Method
(b) Y - X = 1000011 – 1010100
• Subtraction of unsigned numbers: Since, (r - 1)‘s Y = 1000011
complement is one less than the r‘s complement, result 1‘s complement of X = + 0101011
of adding the minuend to the complement of the
Sum = 1101110 There is no end carry.
subtrahend is one less than the correct difference when
an end carry occurs. Y - X = - (1‘s complement of 1101110)
• Adding the end carry to the sum is referred to as an = - 0010001.
end‐around carry.
■Note:
Example-3: Given the two binary numbers X = 1010100 (a) Negative result is obtained by taking the 1‟s
and Y = 1000011, perform the subtraction
complement of the sum, since this is the type of
(a) X - Y and (b) Y - X by using 1‘s complements. complement used.

(a) X - Y = 1010100 – 1000011 X = 1010100 (b) The above procedure with end‐around carry is also
1‘s complement of Y = + 0111100 applicable to subtracting unsigned decimal numbers
Sum = 1 0010000 with 9‟s complement.
End around carry = +1
Answer: X – Y = 0010001
Signed Number Representation

• Positive integers (including zero) can be represented as unsigned numbers.


• In ordinary arithmetic, minus sign indicates a negative number and plus sign indicates a positive number. Similarly,
negative integers in binary representation also require a notation for negative values.
• Thus, a sign bit placed in the leftmost position of the number represents the sign, „0‟ means positive and „1‟ means
negative sign.
• All signed or unsigned binary numbers are basically a string of bits. It is the user who determines whether the number is
signed or unsigned. If the binary number is signed, then the leftmost bit is the sign bit and rest of the bits represent the
number. If the binary number is an unsigned number, then the leftmost bit is the most significant bit of the number.
• For Example: the string 01001 can be considered as 9 (unsigned binary) or as +9 (signed binary)
because the leftmost bit is 0.
• String 11001 represents the binary equivalent of 25 when considered as an unsigned number and the
binary equivalent of -9 when considered as a signed number because the „1‟ in the leftmost position is a
negative sign bit and the other four bits represent binary 9.
• If type of representation is known in advance, there is no confusion.
Signed Number Representation Sign Bit Magnitude Convention
• Representation of the Signed Numbers: In this, representation of positive and negative decimal
Notation has numbers is done by using MSB as the „sign‟ bit, with a
Signed‐Magnitude one Sign bit ‗0‘ denoting a plus sign.
Convention and rest ‗1‘ denoting a minus sign.
Magnitude bits
Remaining bits represent magnitude.
• For ease of arithmetic operations, it is more convenient to In 8-bit representation, MSB represents the sign and
use signed complement system, for negative numbers. remaining seven bits represent the magnitude.
Example: +ve Sign Magnitude
1‟s Complement Bit
Signed‐Complement Format
8-bit representation of +53 is 0 0 1 1 0 1 0 1
System and −53 is 1 0 1 1 0 1 0 1
2‟s Complement
Format - ve Sign Magnitud
M Bit e
a Range of an n−bit Signed Bit Magnitude representation
g
is −(2n−1 − 1) to +(2n−1 − 1). Thus range of 8-bit
n
i
representation of decimal numbers is from −127 to +127
t using the sign-bit magnitude format.
u
There are two representations for Zero.
d
e
Signed Complement Representation
1's Complement Format
In the 1‘s complement format, the positive numbers remain unchanged i.e. the bits of these numbers will have
natural binary weightage with a leading “0”.
The negative numbers are obtained by taking the 1‟s complement of the positive counterparts.
For example: +9 is 00001001 in eight-bit notation. −9 is 11110110, which is 1‘s complement of 00001001.
n-bit notation represents numbers in the range from −(2 n−1−1) to +(2 n−1−1) using the 1‘s complement format.
8-bit representation of the 1‘s complement format can represent decimal numbers in the range from −127 to +127.
There are two representations for Zero.
2's Complement Format
MSB represents the sign bit, ‗0‘ for a plus sign and a ‗1‘ for a minus sign. Remaining bits represent the magnitude.
Positive Numbers are represented in the same way as in case of sign-bit or 1‘s complement representation.
Negative Numbers are represented by the 2‘s complement of their positive counterparts.
Example: +9 is 0 0 0 0 1 0 0 1 and −9 is 1 1 1 1 0 1 1 1

If the 2‘s complement of the magnitude of +9 gives a magnitude of −9, then the reverse process will also be true, i.e. the 2‘s
complement of the magnitude of −9 will give a magnitude of +9.
The n-bit notation of the 2‘s complement format can be used to
represent all decimal numbers in the range from :
−(2n−1) to +(2n−1 − 1)  -128 to +127
Note: Sign bit Magnitude and 1's complement formats have two zeros each,
while 2's complement format has one zero.
Decimal Equivalent of 2‘s Complement Format
2's Compliment Number: 00001110 2's Compliment Number: 10001110
MSB bit is ‗0‘, which indicates a plus sign. MSB bit is ‗1‘, which indicates a minus sign
Magnitude bits are obtained from last 7 bits
Magnitude bits are 0001110.
(0001110) of the given number by getting its 2's
Decimal equivalent compliment: → 1110010
= 0×26 + 0×25 + 0×24 +1×23+ 1×22 +1×21 + 0×20 Decimal Value
=0 + 0 + 0 + 8 + 4 + 2 + 0 = 1×26 + 1×25 + 1×24 +0×23+ 0×22 +1×21 + 0×20
= 14 = 64 + 2 + 16 + 0 + 0 + 2 + 0
= 114  Add minus sign to it as MSB=1
Therefore, 00001110 represents +14
Therefore, 10001110 represents −114

Alternate Method:
1 0 0 0 1 1 1 0
-128 8 4 2 Weight of MSB of –ve
number is taken as
negative value

Add all the = - 128 + 14 = -114


weights
Addition of Binary Numbers
Addition Using the 2‘s Complement Method
 2‘s complement is the most commonly used code for processing positive and negative
binary numbers. It forms the basis of arithmetic circuits in modern computers.

 Addition of numbers expressed in 2‘s complement form follows the basic laws of binary
addition. However, the final carry , if any, while adding MSBs is disregarded.

 Four cases to be considered for explaining 2‘s compliment method of addition are:-
 Case-1: Both the numbers are positive.
 Case-2: Larger of the two numbers is positive.
 Case-3: Larger of the two numbers is negative.

 Case-4: Both the numbers are negative


Addition Using the 2‘s Complement Method
Case 1: Both numbers to be added are positive Addition of the two numbers, +37 and +18, is
performed as follows
Add decimal numbers +37 and +18.
37 00100101
2‘s complement form of +37 in 8-bit representation = 00100101
18 +00010010
2‘s complement form of +18 in 8-bit representation = 00010010 55 00110111
The decimal equivalent of (00110111)2 is (+55).

Case 2: Larger of the two numbers is positive Addition of the two numbers +37 and −18, is performed
Two decimal numbers are +37 and -18. as follows:
2‘s complement form of +37 in 8-bit representation = +37 00100101
00100101 -18 11101110
2‘s complement form of −18 in 8-bit representation = 19 100010 011
11101110 Final carry is to be disregarded.
After disregarding carry, decimal equivalent of
(00010011)2 is +19.
128 64 32 16 8 4 2 1
Addition Using the 2‘s Complement Method -37 11011011
+18 +00010010
Case 3: Larger of the two numbers is negative
Two decimal numbers +18 and −37. -19 11101101

2‘s complement form of -37 in 8−bit representation Since MSB of the result (11101101)2 is ―1‖, it is a
=11011011 negative number and is in 2‘s complement form.
2‘s complement form of +18 in 8−bit representation To find the decimal equivalent, take the 2‘s complement
=00010010 of (11101101)2 convert to decimal equivalent and
Addition of the two numbers, −37 and +18, is performed as: precede the number with a negative sign.
Final result is −19.

Case 4: Both numbers too be added are negative


Two decimal numbers are −18 and −37. -37 11011011
2‘s complement form of −18 in eight−bit representation -18 +11101110
=11101110 -55 111001001
2‘s complement form of −37 in eight−bit representation
=11011011 Final carry from MSB position is disregarded.
Addition of the two numbers, −37 and −18, is performed as: The decimal equivalent of (11001001)2, which is in 2‘s
complement form, is −55.

128 64 32 16 8 4 2 1
Summary of Addition Using the 2‘s Complement Method
 2‘s complement addition method can be used when the expected result of addition lies in the range from −2n−1 to
+(2n−1− 1), where ―n‖ being the number of bits used to represent the numbers.
 Eight-bit 2‘s complement arithmetic cannot be used to perform addition if the result of addition lies outside the range
from −128 to +127.
 Steps to be followed for addition in 2‘s complement arithmetic:
 Represent the two numbers to be added in 2‘s complement form.
 Add using basic rules of binary addition.
 Disregard the final carry, if any.
 Result of addition is in 2‘s complement form.

Example: Confirm validity of 16-bit 2‟s complement addition method for 14276 and 18490.
Range of 16-bit 2‟s complement arithmetic is −215 to +(215− 1), i.e. −32768 to +32767.
The expected result 32766 of adding 14276 and 18490 is inside the allowable range and
hence the method can be used to add the given numbers.
2‘s Complement Arithmetic To make sure that result falls within the range, number of
bits in its representation would have to be increased.
Example: Add −118 and −32 firstly using eight-bit 2‟s
complement arithmetic. Example: Refer previous slide where -118 and -32 were in
8-bit representation. Now −118 and −32 are in 16-bit 2‟s
Solution: complement representation and the numbers are to be added.
−118 in eight-bit 2‘s complement form = 1 0 0 0 1 0 1 0
−32 in eight-bit 2‘s complement form = 1 1 1 0 0 0 0 0 Solution
−118 in 16-bit 2‘s complement form = 1111111110001010
Result after Adding two numbers: 101101010
−32 in 16-bit 2‘s complement form = 1111111111100000
After disregarding the final carry, decimal equivalent of Addition of the two numbers, 11111111101101010
(01101010)2 is +106. However, this is not correct.
Reason for the wrong result is that the expected result, i.e. – After disregarding the final carry, decimal equivalent
−150, lies outside the range of eight-bit 2‟s complement of (1111111101101010)2, which is in 2‘s complement
form, is −150.
arithmetic. Such a condition is called OVERFLOW. We will
learn detection of overflow condition later – 16-bit 2‘s complement arithmetic has produced the
As of now, we must remember that 8-bit 2‘s complement correct result, as the expected result lies within the
arithmetic is applicable for results that lie in the range from range of 16-bit 2‟s complement notation.
−2(8-1) to + (2(8-1) − 1), i.e. −27 to + (27 − 1)  −128 to +127.
Example: Convert to binary form and Add (275.75)10 + (37.875)10
 Convert the given decimal numbers into their binary forms :
(275.75)10 = (100010011.11)2
(37.875)10 = (100101.111)2
 Align the radix points of the two binary numbers and ensure that same number of bits are present in their
integer and fractional parts: 1 0 0 0 1 0 0 1 1 . 1 1 0
000100101.111
100111001.101
 Decimal equivalent of (100111001.101)2 is (313.625)10.
Example: Add two hex numbers (AF1.B3)16 + (FFF.E)16
(AF1.B3)16 = (101011110001.10110011)2
(FFF.E)16 = (111111111111.1110)2
 Align the radix points of the two binary numbers and ensure that same number of bits
are present in their integer and fractional parts:
101011110001.10110011
111111111111.11100000
1101011110001.10010011
 Hexadecimal equivalent of (1101011110001.10010011)2 is obtained by making groups of four
bits on each side of radix point, starting from radix point:- (0001 1010 1111 0001.1001 0011)2
 Result is (1AF1.93)16, which is equal to the hex addition of (AF1.B3)16 and (FFF.E)16.
Subtraction
of
Binary Numbers
Subtraction of Binary Numbers
 Subtraction is done column-wise .
 Subtract the LSBs and subsequently proceed towards the MSB.
 Wherever the subtrahend > minuend, borrow is taken from the next adjacent higher bit equal to ‗1‘ in the Minuend.
In case next higher bit in the Minuend is ―0‖, then borrow is taken from the next higher bit and so on, After a borrow
has been given by a bit in the Minuend, that bit becomes ‗0‘ and all the intervening bits become ‗1‘:

0 1 10 0 1 10 0 1 10
Minuend  1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0
Subtrahend  1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1
1 1 1 0 1 1 0 0 1 1

 ‗1‘ is borrowed from the second MSB position, leaving a ‗0‘ in that
position. The borrow is first brought to the third MSB position to make
it ‗10‘.
 Out of ‗10‘ at third MSB position, ‗1‘ is taken to the LSB position to
make ‗10‘ there, leaving a ‗1‘ in the third MSB position.
 10−1 in the LSB column gives ‗1‘,
 1 − 0 in the third MSB column gives ‗1‘,
 0 − 0 in the second MSB column gives ‗0‘ and
 1 − 1 in the MSB also gives ‗0‘ to complete subtraction.
Subtraction Using 2`s Complement Arithmetic
 Subtraction is similar to addition. 2‟s complement Subtraction Method has following
 In 2‘s complement notation, positive magnitudes are the straight six relevant cases:-
binary numbers, while the negative magnitudes are 2‘s
complement of their straight binary counterparts. Case 1: Both minuend and subtrahend are
 In 2‘s complement arithmetic, answer is also in 2‘s complement positive. Subtrahend is the smaller of the two.
notation, with the MSB indicating the sign and the remaining Case 2. Both minuend and subtrahend are
bits indicating the magnitude. positive. Subtrahend is the larger of the two.
 A „0‟ in MSB position is a positive sign, and a „1‟ is a negative sign. Case 3. The minuend is positive. Subtrahend is
 Steps to do subtraction in 2‘s complement arithmetic are: negative and smaller in magnitude.
Represent the minuend and subtrahend in 2‘s complement form. Case 4. The minuend is positive. Subtrahend is
Find the 2‘s complement form of the subtrahend. negative and greater in magnitude.
Add the 2‘s complement of the subtrahend to the minuend. Case 5. Both minuend and subtrahend are
negative. Minuend is the smaller of the two.
Disregard the final carry, if any. Result is in 2‘s complement form
Validity of 2‟s complement Subtraction Method: If the expected Case 6. Both minuend and subtrahend are
result of subtraction lies in the range from −2n−1 to +(2n−1− 1), negative. Minuend is the larger of the two..
“n” being the number of bits used to represent the numbers.
Subtraction Using 2`s Complement Arithmetic
Case 1: Both minuend and subtrahend are Case 2. Both minuend and subtrahend are positive.
positive. Subtrahend is the smaller of the two. Subtrahend is the larger of the two.
Example: Subtract +24 from +14.
Example: subtract +14 from +24. 2‘s complement form of the Minuend
Step-1: 2‘s complement form of the Minuend
+14 = 00001110
+24 = 00011000
2‘s complement form of the Subtrahend
Step-2: 2‘s complement form of the Subtrahend
+24 = 00011000
+14 = 00001110 Find 2‘s complement of the Subtrahend
Step-3: Find 2‘s complement of the subtrahend −(+24)=11101000
−(+14) = 11110010
Add the numbers obtained in step 2 & 3 above
Add the numbers obtained in Step-2 & 3 above to get [+14 - (+24)]
to get [+24 - (+14)]: 0 0 0 0 1 1 1 0
0 0 0 1 1 0 0 0
+1 1 1 1 0 0 1 0 +1 1 1 0 1 0 0 0
1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 1 0

• Disregard the final carry. Balance number • Since MSB = 1, result is a negative number. Therefore.
is a +ve number because MSB=0 we have to take its 2‟s complement to obtain the
• Decimal equivalent of (00001010)2 is +10 decimal number and add ‗-‘ sign to it.
• Decimal equivalent of (11110110)2 after taking 2‘s
complement with negative sign is −10.
128 64 32 16 8 4 2 1
Subtraction Using 2`s Complement Arithmetic
Case 3: The minuend is positive. Subtrahend is Case 4. The minuend is positive. Subtrahend is negative and
negative and smaller in magnitude. greater in magnitude.
Example: Subtract −14 from +24. Example: Subtract −24 from +14.
Step-1: 2‘s complement form of the Minuend Step-1: 2‘s complement form of the Minuend
+24 = 00011000 +14 = 00001110
Step-2: 2‘s complement form of the Subtrahend Step-2: 2‘s complement form of the Subtrahend
−14 = 11110010 −24 = 11101000
Step-3: 2‘s complement of the subtrahend
Step-3: 2‘s complement of the subtrahend
-(−24) = 00011000
− (−14) = 00001110
Add the numbers obtained in step 2 & 3 above to
Add the numbers obtained in step 2 & 3 above
get [+14 − (−24)]:
to get [+24 − (−14)]
+ 24 0 0 0 1 1 0 0 0 + 14 0 0 0 0 1 1 1 0
-(-24 +0 0 0 1 1 0 0 0
- (-14) + 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 0
0 0 1 0 0 1 1 0 Since MSB=0, the result is a positive number and 2‟s
Decimal equivalent of (00100110)2 is +38. complement notation of positive numbers is the same as
their straight binary representation with MSB=0. Thus
decimal equivalent of (00100110)2 is +38.
128 64 32 16 8 4 2 1
Subtraction Using 2`s Complement Arithmetic
Case 5. Both minuend and subtrahend are negative. Case 6. Both minuend and subtrahend are negative.
Minuend is the smaller of the two. Minuend is the larger of the two.
Example: Subtract −14 from −24. Example: Subtract −24 from −14 (i.e. -14 +24)
Step-1: 2‘s complement form of the Minuend Step-1: 2‘s complement form of the Minuend
−24 = 11101000 −14 = 11110010
Step-2: 2‘s complement form of the Subtrahend Step-2: 2‘s complement form of the Subtrahend
−14 = 11110010 −24 = 11101000
Step-3: 2‘s complement of the subtrahend
Step-3: 2‘s complement of the subtrahend
−(−14) = 00001110
−(−24)= 00011000
Add the numbers obtained in step 2 & 3 above
Add the numbers obtained in step 2 & 3 above
to get [-24 − (−14)]:
to get [−14 −(−24)]:
-24 1 1 1 0 1 0 0 0
-(-14) +0 0 0 0 1 1 1 0 - 14 1 1 1 1 0 0 1 0
1 1 1 1 0 1 1 0 -(-24) +0 0 0 1 1 0 0 0
1 0 0 0 0 1 0 1 0
• Decimal equivalent of (11110110)2, which is in 2‘s
complement form, is −10 Disregard the final carry.
Decimal equivalent of (00001010)2, which is +10.
.
Example
Example: Subtract (1110.011)2 from (11011.11)2 using basic rules of binary subtraction and verify the result by showing
equivalent decimal subtraction.
Solution: Minuend and subtrahend are first modified to have the same number of bits in the integer and fractional parts.

Example: Subtract (−64)10 from (+32)10 . Use 2‟s complement arithmetic.


Solution: So the operation that we have to perform is (+32)10 – (-64)10
(+32)10 in 2‘s complement notation = (00100000)2
(−64)10 in 2‘s complement notation = (11000000)2
2‘s complement of (−64)10 will give  -(-64)= (01000000)2
(+32)10 − (−64)10 is determined by adding the 2‘s complement of (−64)10 to (+32)10
Since MSB of the result is „0‟, it is a positive number.
Thus, the 2‟s complement notation for positive numbers is
the same as its straight binary code with a preceding „0‟
at MSB. The decimal equivalent of (01100000)2 is +96.
Example: Subtract (−64)10 from (+32)10 . Use 2‟s complement arithmetic.
Solution: So the operation that we have to perform is (+32)10 – (-64)10
(+32)10 in 2‘s complement notation = (00100000)2
(−64)10 in 2‘s complement notation = (11000000)2
2‘s complement of (−64)10 will give  -(-64)= (01000000)2
(+32)10 − (−64)10 is determined by adding the 2‘s complement of (−64)10 to (+32)10
Since MSB of the result is „0‟, it is a positive number. Thus, the 2‟s complement notation for positive numbers is the
same as its straight binary code with a preceding „0‟ at MSB. The decimal equivalent of (01100000)2 is +96.
Example: Subtract (29.A)16 from (4F.B)16. Use 2‟s complement arithmetic.
Minuend (4F.B)16 = (01001111.1011)2
Minuend in 2‟s complement form = (01001111.1011)2
Subtrahend (29.A)16 = (00101001.1010)2
2‟s complement of the subtrahend = (11010110.0110)2
(4F.B)16 −(29.A)16 is given by the addition of 0 1 0 0 1 1 1 1.1 0 1 1
4FB & 2‟s complement of subtrahend 29A +1 1 0 1 0 1 1 0 . 0 1 1 0
10 0 1 0 0 1 1 0.0 0 0 1
Disregard the final carry.
Since the result is a positive number, 2‟s complement notation is the same as its
straight binary code. Hex equivalent of the resulting binary number is (26.1)16.
1's Complement Arithmetic
Subtraction by 1's Complement
The steps to be followed in subtraction by 1‘s •Example: Solve (110101)2 – (100101)2
complement are: •Solution: Let us see what these numbers are whose binary
Write down 1‟s complement of the subtrahend. representation is given: (110101)2  (53)10
To add this with the minuend. (100101)2  (37)10
Step-1: Make sure both binary numbers have same number of
If the result of addition has a carry over then a bits and follow the convention of +ve / -ve numbers in 1‘s
‗1‘ is added in the last bit of the result. complement representation.
If there is no carry over, then the result obtained is Step-2: Since calculation that needs to be performed is
final. The result so obtained is in 1‘s complement (53 - 37)10, we will take the 1‟s complement form of -3710
form. Positive result will have leading zero and (+37) 8-bit (-37) 1‘s Comp
negative result will have a leading ‗1‘. 1‘s complement of (37)10  0010 0101  1101 1010
If it is negative a negative number, then we will have Minuend - 0 0 1 1 0 1 0 1
to take its 1‘s complement and add a minus sign to it. 1‘s complement of subtrahend - 1 1 0 1 1 0 1 0
Add minuend and Subtrahend - 1 0 0 0 0 1 1 1 1
Add Carry over to the result 1
0 0 0 1 0 0 0 0
Result: Difference of (53 - 37)10 is 00010000 = (16)10
Subtraction by 1's Complement
Example: (101011)2 – (111001)2  43 – 57 = -14 Example: Solve (1011.001)2 – (110.10)2
Solution: 1‘s complement of 00111001 is 11000110 Solution: Decimal equivalent of given binary numbers
Minuend: 00101011 (1011.001)2  11.125 and (110.10)2  6.5
1‘s complement form of -57: 11000110 • 1‘s complement representation of 11.125 is  01011.001
11110001
• MSB =1, result is a –ve number. • Since the calculation to be performed is 11.125 – 6.5, we
• Take 1's Comp & add '-‗ minus sign) need to find the 1‘s complement representation of (-6.5) after
making sure that number of bits in binary representation
Hence the difference is (– )0 0 0 0 1 1 1 02 = -1410 before and after the radix point are same as that of 11.125
• 1‘s complement representation of -6.5 is  11001.011
Minuend: 01011.001
1‘s complement of subtrahend: 11001.011
Carry over: 1 0 0 1 0 0 . 1 0 0
Add carry: 1
00100.101
• Since MSB = 0, result is a +ve number and can be directly
converted to decimal representation.
Hence the required difference is 00100.1012 = 4.62510
Subtraction by 1's Complement What is an Over Flow condition?
An overflow occurs when two “n” bit numbers are added and
Example: Solve (10110.01)2 – (11010.10)2 the sum is a number with n + 1 bits. This is true for binary or
decimal numbers, signed or unsigned.
Solution: Since 11010.10 is to be subtracted from
Overflow is an issue in digital computers because n + 1 bits
10110.01, we will find 1‘s complement of 011010.10
cannot be accommodated by an n -bit word. For this reason,
which is  100101.01
overflow needs to be detected
Minuend: 0 1 0 1 1 0 . 0 1
How to detect Over Flow condition?
1‘s complement of subtrahend: 1 0 0 1 0 1 . 0 1
111011.10 Detection of an overflow after adding two binary numbers
depends on whether the numbers are signed or unsigned.
• Since MSB =1, result is a –ve number.
Unsigned Numbers: When two unsigned numbers are added,
• Take 1's Comp & add '-‗ minus sign)
an overflow is detected from the end carry out of the most
Hence the difference is – 000100.01 i.e. – 100.012 significant position.
- 4.2510 Signed Numbers: Leftmost bit represents the sign, and
negative numbers are in 2‘s-complement form. When two
signed numbers are added, the sign bit is treated as part of the
number and following points need to be borne in mind:
An overflow cannot occur after an addition if one
number is positive and the other is negative.
An overflow may occur if the two numbers added are
both positive or both negative. v
The end carry does not indicate an overflow.
Example: Two signed binary numbers represented in 8-bit form can have a range from +127 to binary -128. Addition
result of +70 & +80 OR -70 + (-80), is either +150 OR –150 and exceeds the capacity of eight-bits.

Carry-out Cout 0 1 Carry-in Cin Carry-out Cout 1 0 Carry-in Cin

+70 0 100 0110 -70 1 011 1010


+80 0 101 0000 -80 1 011 0000
+150 1 001 0110 -150 1 0 1 1 0 1 0 1 0
For addition of two +ve numbers 70 + 80, the sign bit of the result should have been +ve (0), but it is negative (1). If
the carry out of sign bit (0) is taken as the sign bit of the result, then the 9-bit answer will be correct.
For addition of two -ve numbers -70 - 80, the sign bit of result should have been -ve (1), but it is “0” i.e.
positive. If the carry out of sign bit (1) is taken as the sign bit of the result, then the 9-bit answer will be
correct.
The conclusion from above example is that 8-bit representation cannot accommodate the result. Since the answer
cannot be accommodated within eight bits, an overflow condition is declared.
An overflow condition is detected by observing the carry into the sign bit position and the carry out of the sign bit
position. If these two carries are not equal, an overflow has occurred.

Overflow Condition Cin ≠ Cout


No Overflow Cin = Cout
Solve following questions
(a) Find 1‘s complement & 2‘s complement representation of 88 and 77
(b) Add 88 & 77 using 2‘ and check overflow. How will you
overcome overflow problem
(c) Subtract 88 - 77 using 2‘ and 1‘s Comp. Arith.
(d) Subtract 77 - 88 using 2‘ and 1‘s Comp. Arith.

88
0 1 0 1 1 0 0 0 +ve number
1 0 1 0 0 1 1 1 1’s Comp form of -88

1 0 1 0 1 0 0 0 2’s Comp form of -88

77
0 1 0 0 1 1 0 1 +ve number
1 0 1 1 0 0 1 0 1’s Comp form of -77

1 0 1 1 0 0 1 1 2’s Comp form of -77

128 64 32 16 8 4 2 1
Binary Codes
Binary Codes For Decimal Numbers
When numbers, letters or special words are represented by a special group of symbols, the group of such
symbols are called Codes.
Group of 1's and 0's assigned to represent numbers/letters are called Binary Codes. Binary Codes are of broadly
categorized as:-
Numeric Codes: are used to represent numbers.
Alphanumeric Codes: are used to represent alphabets and numbers.
Decimal numbers can be coded as Straight Binary Representation.
Straight binary representation is useful for operation of digital systems but external world conforms to
decimal system.
However, conversion from binary to decimal format can be long and complicated for large numbers.
To simplify this process, different codes, that combine some features of decimal and binary systems, are
employed for representing Decimal numbers.
Codes for Decimal digits require a minimum of four bits. Numerous different codes can be obtained by
arranging four or more bits in ten different possible combinations. These codes are Weighted or Non-weighted.
Binary Coded Decimal Numbers
Weighted codes, obey position weighting system i.e. position of each binary digit represents
the positional value (weight). Positions of bits can be positively weighted or negatively
weighted.
Binary-Coded-Decimal (BCD) Code: Binary Coded Decimal (BCD) code is a
positively weighted system. It uses natural weights i.e. 8421 being the weights of the
four bits. Each digit of a decimal number is represented by a separate binary equivalent
number (with natural weighting) as shown below:-
Decimal No. (185)10 1 8 5
BCD Representation of (185)10 0001 1000 0101
Binary Representation (185)10 : (10111001)2

Non-weighted codes do not have positional weighting system. Excess-3 (XS-3) code and
Gray Code are non-weighted codes. Refer next slide for Gray Codes.
BCD Addition
• Consider the addition of two decimal digits in BCD, three situations arise:
• Addition does not result in a carry and result is ≤ 9. Corresponding result is correct BCD value.
• Addition does not result in a carry, but it is > 9 and is not a correct BCD value. Requires Correction
by addition of binary ‗6‘ to obtain the final corrected BCD value.
• Addition results in a carry, though values are valid BCD codes but final result is not correct. Requires
Correction by addition of binary ‗6‘ to obtain the final corrected BCD value.
• Consider the following three BCD additions:
4 0100 4 0100 8 1000
+ 5 +0101 +8 +1000 +9 1001
9 1001 12 1100 17 10001
+ 0110 + 0110
1 0010 1 0111
BCD Addition
• Addition of two n‐digit unsigned BCD numbers follows the same procedure.
• Consider the addition of 184 + 576 = 760 in BCD:

Carry 1 1
BCD Number 0001 1000 0100 184
BCD Number +0101 0111 0110 +576
Binary sum 0111 1 0000 1010 760
Add 6 0110 0110
BCD sum 0111 0110 1 0000 760

• The first, least significant pair of BCD digits produces a BCD digit sum of 0000 and a carry for the next pair of digits.

• The second pair of BCD digits plus a previous carry produces a digit sum of 0110 and a carry for the next pair of digits.

• The third pair of digits plus a carry produces a binary sum of 0111 and does not require a correction.
BCD Codes

• Note: 8421 binary code is referred as Natural Binary Coded Decimal code (NBCD)
•Since there are many possible weights that can be assigned to derive BCD code, there are following two properties
that give some figure of merit to a code over another Code: Self-Complementing Property and Reflective Property.
Gray Code
 Gray code is a non-weighted code and is not suitable for arithmetic
operations.
 Gray Code is a unit distance code in which each successive code
word differs from the preceding code in only one bit position.
 Gray code is also a ―Reflective Code”.
 An N-bit Gray code can be obtained by reflecting N-1 bit code about
an axis at the end of the code and putting the
MSB of 0 above the axis and
MSB of 1 below the axis.
Binary to Gray Code Conversion
 Binary to Gray code converter converts binary code to  Binary to Gray (4-bit) code conversion table is given below:
equivalent gray code.
 Gray code is a non weighted code and each successive gray
code differs in one bit position.
G4G3G2G1
Gn = Bn
Gn-1 = Bn XOR Bn-1
Gn-2 = Bn-1 XOR Bn-2
Gn-3 = Bn-2 XOR Bn-3
And so on for all bits
Example: Generate the Gray code of following binary numbers (a) 101101 (b) 110110

(a) 1 0 1 1 0 1
1 0 1 1 0 1

1 1 1 0 1 1
1 1 0 1 1 0
(b) 1 1 0 1 1 0

1 0 1 1 0 1
Gray To Binary Conversion

Given Gray Code

Binary Code
Output

Example: Convert Gray Code 100110 in to its binary code


XOR
Operation
Given Gray Code 1 0 0 1 1 0

Binary Code 1 1 1 0 1 1
Output
Code Conversion BCD Code to Excess-3 Code Conversion
Binary Binary to Gray Code Conversion
Code 
Excess-3 Code = BCD Code + 3
No. BCD Code Excess-3
Code Code
Gray
Code 
0 0000 0011
XOR
Operation 1 0001 0100
2 0010 0101
Gray to Binary Code Conversion
Gray 3 0011 0110
Code 
4 0100 0111
5 0101 1000
Binary 6 0110 1001
Code 
7 0111 1010
8 1000 1011
9 1001 1100
Alphanumeric Codes

Alphanumeric codes represent numbers, alphabetic, numeric and other characters such
as special symbols and various instructions necessary for conveying information.
Following are the three alphanumeric codes very commonly used for data representation.
ASCII: 7-bit American Standard Code for Information Interchange.
EBCDIC: 8-bit Extended Binary Coded Decimal Interchange Code.
Baudot (Hollerith): Five bit Code.

ASCII code is more commonly used worldwide while EBCDIC is used primarily in large
IBM computers.
ASCII Codes
Alphanumeric Codes

Note: Above is an example and not a comprehensive list of alphanumeric codes


Binary Logic
• Binary logic deals with binary variables with two discrete values (true and false) and with operations having logical
meaning.
• Variables are designated by letters of the alphabet, such as A, B, C, x, y, z, etc., with each variable having two and only
two distinct possible values: 1 and 0.
• AND: Operation is represented by a dot or by the absence of an operator.
For example, x . y = z or xy = z is read ―x AND y is equal to z.‖ AND operation is interpreted to mean
that z = 1 if and only if x = 1 and y = 1; otherwise z = 0.
• OR: Operation is represented by a plus sign.
For example, x + y = z is read as ―x OR y is equal to z,‖ meaning that z = 1 if x = 1 or if y = 1 or if both
x = 1 and y = 1. If both x = 0 and y = 0, then z = 0.

• NOT: Operation is represented by a prime (sometimes by an overbar).


For example, x = z (or x = z ) is read ―not x is equal to z,‖ meaning that z is opposite of x .
In other words, if x = 1, then z = 0, but if x = 0, then z = 1. The NOT operation is also referred to as the
complement operation.
Binary Logic
• Binary logic resembles binary arithmetic, and the operations
AND / OR have similarities to multiplication and addition.
Binary Logic: A logic variable is always either 1 or 0.
In binary arithmetic:
1 + 1 = 10 (is read as ―one plus one = 2‖).
In binary logic:
1 + 1 = 1 (is read as ―one OR one = one‖).

• Truth tables and logic symbols of AND, OR and NOT are


presented in the adjacent diagrams. However, new symbology
promulgated vide IEEE/ANSI standards will be discussed in a
later module.
XOR and XNOR Gates
• Truth table of XOR Gate: Truth table of XNOR gate:
A B Y A B Y
0 0 0 0 0 1
0 1 1 0 1 0
1 0 1 1 0 0
1 1 0 1 1 1

Y = A.B + A. B Y = A.B + A. B

Y Y
End

You might also like