Professional Documents
Culture Documents
• 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.
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
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
(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
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
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 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.
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.
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
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
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
Binary Code
Output
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
Y = A.B + A. B Y = A.B + A. B
Y Y
End