UNIT - I Part-1
UNIT - I Part-1
Part – I
Introduction to number systems,
Complement representation of negative
numbers, binary arithmetic
3/25/2023 2
NUMBER SYSTEMS & CODES
Positional Number Systems
3/25/2023 5
BINARY NUMBERS
3/25/2023 6
As you have seen in Table, four
bits are required to count from
zero to 15. In general, with n
bits you can count up to a
number equal to 𝟐𝒏 − 𝟏.
Largest decimal number = 2𝑛 − 1
For example, with five bits (n =
5) you can count from zero to
thirty-one.
𝟐𝟓 − 𝟏= 32 - 1 = 31
With six bits (n = 6) you can
count from zero to sixty-three.
𝟐𝟔 − 𝟏= 64 - 1 = 63
3/25/2023 7
An Application
Learning to count in binary will help you to basically
understand how digital circuits can be used to count events.
Let’s take a simple example of counting tennis balls going
into a box from a conveyor belt. Assume that nine balls are to
go into each box.The counter in Figure counts the pulses
from a sensor that detects the passing of a ball and produces
a sequence of logic levels (digital waveforms) on each of its
four parallel outputs. Each set of logic levels represents a 4-
bit binary number (HIGH = 1 and LOW = 0), as indicated. As
the decoder receives these waveforms, it decodes each set
of four bits and converts it to the corresponding decimal
number in the 7-segment display.
3/25/2023 8
When the counter gets to the binary state of 1001, it has
counted nine tennis balls, the display shows decimal 9, and a
new box is moved under the conveyor belt. Then the counter
goes back to its zero state (0000), and the process starts
over. (The number 9 was used only in the interest of single-
digit simplicity.)
3/25/2023 9
The weight structure of a binary number is
where n is the number of bits from the binary point. Thus, all
the bits to the left of the binary point have weights that are
positive powers of two, as previously discussed for whole
numbers. All bits to the right of the binary point have weights
that are negative powers of two, or fractional weights. The
powers of two and their equivalent decimal weights for an 8-
bit binary whole number and a 6-bit binary fractional number
are shown
3/25/2023 10
Binary-to-Decimal Conversion
The decimal value of any binary number can be found by
adding the weights of all bits that are 1 and discarding the
weights of all bits that are 0.
Convert the binary whole number 1101101 to decimal.
Solution
Determine the weight of each bit that is a 1, and then find
the sum of the weights to get the decimal number.
3/25/2023 11
Convert the fractional binary number 0.1011
to decimal.
Solution
Determine the weight of each bit that is a 1,
and then sum the weights to get the decimal
fraction.
3/25/2023 12
Decimal to Binary Conversion
Sum-of-Weights Method
To get the binary number for a given decimal number, find the
binary weights that add up to the decimal number.
The decimal number 9, for example, can be expressed as the
sum of binary weights as follows:
3/25/2023 13
Repeated Division-by-2 Method
3/25/2023 14
3/25/2023 15
3/25/2023 16
Converting Decimal Fractions to Binary
3/25/2023 18
3/25/2023 19
Octal Numbers
3/25/2023 20
3/25/2023 21
Octal-to-Decimal Conversion
Since the octal number system has a base of eight, each
successive digit position is an increasing power of eight,
beginning in the right-most column with 𝟖𝟎 . The evaluation of
an octal number in terms of its decimal equivalent is
accomplished by multiplying each digit by its weight and
summing the products, as illustrated here for 𝟐𝟑𝟕𝟒𝟖 .
3/25/2023 22
Decimal-to-Octal Conversion
A method of converting a decimal number to an octal number
is the repeated division by 8 method, which is similar to the
method used in the conversion of decimal numbers to
binary or to hexadecimal. To show how it works, let’s convert
the decimal number 359 to octal
3/25/2023 23
Octal-to-Binary Conversion
Because each octal digit can be represented by a 3-bit binary
number, it is very easy to convert from octal to binary. Each
octal digit is represented by three bits as shown in Table
3/25/2023 24
Binary-to-Octal Conversion
Conversion of a binary number to an octal number is the
reverse of the octal-to-binary conversion. The procedure is
as follows: Start with the right-most group of three bits and,
moving from right to left, convert each 3-bit group to the
equivalent octal digit. If there are not three bits available for
the left-most group, add either one or two zeros to make a
complete group. These leading zeros do not affect the value
of the binary number.
3/25/2023 25
Hexadecimal Numbers
3/25/2023 26
3/25/2023 27
Counting in Hexadecimal
How do you count in hexadecimal once you get to F? Simply
start over with another column and continue as follows:
D, E, F, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A, 1B, 1C, 1D,
1E, 1F, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2A, 2B, 2C, 2D,
2E, 2F, 30, 31,
With two hexadecimal digits, you can count up to 𝑭𝑭𝟏𝟔 ,
which is decimal 255. To count beyond this, three
hexadecimal digits are needed. For instance, 𝟏𝟎𝟎𝟏𝟔 is
decimal 256, 𝟏𝟎𝟏𝟏𝟔 is decimal 257, and so forth. The
maximum 3-digit hexadecimal number is 𝑭𝑭𝑭𝟏𝟔 , or decimal
4095. The maximum 4-digit hexadecimal number is 𝐹𝐹𝐹𝐹16 ,
which is decimal 65,535.
3/25/2023 28
Binary-to-Hexadecimal Conversion
Converting a binary number to hexadecimal is a
straightforward procedure. Simply break the binary number
into 4-bit groups, starting at the right-most bit and replace
each 4-bit group with the equivalent hexadecimal symbol.
3/25/2023 29
Hexadecimal-to-Binary Conversion
3/25/2023 30
It should be clear that it is much easier to deal with a
hexadecimal number than with the equivalent binary
number. Since conversion is so easy, the hexadecimal
system is widely used for representing binary numbers in
programming, printouts, and displays.
Hexadecimal-to-Decimal Conversion
3/25/2023 31
3/25/2023 32
Another way to convert a hexadecimal
number to its decimal equivalent is to
multiply the decimal value of each
hexadecimal digit by its weight and then
take the sum of these products. The weights
of a hexadecimal number are increasing
powers of 16 (from right to left). For a 4-digit
hexadecimal number, the weights are
3/25/2023 33
Decimal-to-Hexadecimal Conversion
3/25/2023 34
3/25/2023 35
Octal to Hexa-Decimal Conversion:
• The simplest way is to initially convert the
given Octal numbers to Binary number and then
the binary number to Hexadecimal number.
• Eg: Convert (756.603)8 to Hexadecimal
3/25/2023 36
Hexa-Decimal to Octal Conversion:
• First convert, Hexa-decimal to Binary and then
convert to Octal.
• Eg: Convert (B9F.AE)16 to Octal
3/25/2023 37
Binary Arithmetic
Binary Addition
The four basic rules for adding binary digits (bits) are as
follows:
Notice that the first three rules result in a single bit and in
the fourth rule the addition of two 1s yields a binary two (10).
When binary numbers are added, the last condition creates a
sum of 0 in a given column and a carry of 1 over to the next
column to the left, as illustrated in the following addition of
011 + 001:
3/25/2023 38
Binary Subtraction
The four basic rules for subtracting bits are as follows:
3/25/2023 39
3/25/2023 40
Let’s examine exactly what was done to subtract the two
binary numbers since a borrow is required. Begin with the
right column.
3/25/2023 41
Binary Multiplication
The four basic rules for multiplying bits are as follows:
3/25/2023 42
3/25/2023 43
Computer Method of Multiplication:
• To perform multiplication, a p-bit Multiplicand
register and 2p-bit Multiplier/Result register is
required.
• The multiplier is placed in the left p-bits of the
Multiplier/ Quotient (MQ) register and the right p-
bits are set to zero.
• Multiplicand is placed in M register.
• The MQ register is then shifted one bit to the left.
• If 1 is shifted out, then add M to MQ.
• If 0 is shifted out, then add 0 to MQ.
• The entire process is repeated p-times.
3/25/2023 44
3/25/2023 45
Binary Division
Division in binary follows the same procedure as division in
decimal,
3/25/2023 46
Computer Method of Division:
3/25/2023 47
3/25/2023 48
9’s Complement and 10’s Complements of
Decimal Numbers:
• Subtraction of Decimal Numbers can be accomplished by
9’s and 10’s complement methods.
9’s Complement:
• The 9’s complement of a decimal number can be obtained
by subtracting each digit of that decimal number from 9.
• Eg: Find the 9’s complement of: (a) 3465 (b) 1264.582
Sol: (a) 9 9 9 9 (b) 9 9 9 9. 9 9 9
3465 1 2 6 4. 5 8 2
6534 8 7 3 5. 4 1 7
3/25/2023 49
10’s Complement:
Eg: Find the 10’s complement of: (a) 4069 (b) 1056.074
Sol: (a) 9 9 9 9 (b) 9 9 9 9 . 9 9 9
4069 1056.074
5930 9’s Complement 8943.925
+1 + 1
5931 10’s Complement 8943.926
3/25/2023 50
9’s Complement Method of Subtraction:
3/25/2023 52
10’s Complement Method of Subtraction:
• To perform Decimal subtraction using 10’s Complement
method, obtain the 10’s complement of the subtrahend
and add it to the minuend.
• If there is a carry, ignore it. The presence of the carry
indicates, the answer is positive, and the result obtain
is itself the answer.
• If there is no carry, it indicates that the answer is
negative and the result obtained is its 10’s
complement.
• Obtain the 10’s complement of this result and place a
negative sign in front to get the answer.
3/25/2023 53
Eg: Subtract the following numbers using 10’s
complement method of subtraction.
3/25/2023 54
Complements of Binary Numbers
Finding the 1’s Complement
The 1’s complement of a binary number is found by changing
all 1s to 0s and all 0s to 1s,
as illustrated below:
3/25/2023 55
Finding the 2’s Complement
The 2’s complement of a binary number is found by adding 1
to the LSB of the 1’s complement. 2’s complement = (1’s
complement) + 1
3/25/2023 56
An alternative method of finding the 2’s complement of a
binary number is as follows:
1. Start at the right with the LSB and write the bits as they
are up to and including the first 1.
2. Take the 1’s complements of the remaining bits.
3/25/2023 57
The 2’s complement of a negative binary number can be
realized using inverters and an adder, as indicated in Figure.
This illustrates how an 8-bit number can be converted to its
2’s complement by first inverting each bit (taking the 1’s
complement) and then adding 1 to the 1’s complement with
an adder circuit.
3/25/2023 58
To convert from a 1’s or 2’s complement back to the true
(uncomplemented) binary form, use the same two procedures
described previously. To go from the 1’s complement back to
true binary, reverse all the bits. To go from the 2’s
complement form back to true binary, take the 1’s
complement of the 2’s complement number and add 1 to the
least significant bit.
3/25/2023 60
The decimal number -25 is expressed as
10011001
Notice that the only difference between +25 and -25 is the
sign bit because the magnitude bits are in true binary for
both positive and negative numbers.
In the sign-magnitude form, a negative number has the same
magnitude bits as the corresponding positive number but the
sign bit is a 1 rather than a zero.
3/25/2023 62
Again, using eight bits, let’s take decimal number -25 and
express it as the 2’s complement of +25 (00011001).
Inverting each bit and adding 1, you get -25 = 11100111
In the 2’s complement form, a negative number is the 2’s
complement of the corresponding positive number.
3/25/2023 63
The Decimal Value of Signed Numbers
Sign-Magnitude
Decimal values of positive and negative numbers in the sign-
magnitude form are determined by summing the weights in
all the magnitude bit positions where there are 1s and
ignoring those positions where there are zeros. The sign is
determined by examination of the sign bit.
3/25/2023 64
1’s Complement
Decimal values of positive numbers in the 1’s complement
form are determined by summing the weights in all bit
positions where there are 1s and ignoring those positions
where there are zeros. Decimal values of negative numbers
are determined by assigning a negative value to the weight
of the sign bit, summing all the weights where there are 1s,
and adding 1 to the result.
3/25/2023 65
3/25/2023 66
2’s Complement
• Decimal values of positive and negative numbers in
the 2’s complement form are determined by
summing the weights in all bit positions where
there are 1s and ignoring those positions where
there are zeros. The weight of the sign bit in a
negative number is given a negative value.
Special case in 2’s complement representation:
• Whenever a signed number has a 1 in the sign bit
and all 0s for the magnitude bits, the decimal
equivalent is - 𝟐𝒏 , where n is the number of bits in
the magnitude.
• Eg: 1000=-8 and 10000=-16
3/25/2023 67
3/25/2023 68
From these examples, you can see why the 2’s complement
form is preferred for representing signed integer numbers: To
convert to decimal, it simply requires a summation of
weights regardless of whether the number is positive or
negative. The 1’s complement system requires adding 1 to
the summation of weights for negative numbers but not for
positive numbers. Also, the 1’s complement form is generally
not used because two representations of zero (00000000 or
11111111) are possible.
3/25/2023 69
Range of Signed Integer Numbers
3/25/2023 70
For 2’s complement signed numbers, the range of
values for n -bit numbers is
Range = -( 𝟐𝒏−𝟏 ) to +( 𝟐𝒏−𝟏 - 1)
where in each case there is one sign bit and n -1
magnitude bits. For example, with four bits you can
represent numbers in 2’s complement ranging from
-𝟐𝟑 = -8 to 𝟐𝟑 -1 = +7.
Similarly, with eight bits you can go from -128 to
+127, with sixteen bits you can go from -32,768 to
+32,767, and so on. There is one less positive
number than there are negative numbers because
zero is represented as a positive number (all zeros).
3/25/2023 71
Example For n=4 Example:
Decimal 2’s Decimal 2’s Representation of -4 in
Complement Complement 2’s complement form
+4=0100
+0 0000 -8 1000 -4=2’s complement of
0100=1011+1
+1 0001 -7 1001 =1100
+2 0010 -6 1010
+3 0011 -5 1011
+4 0100 -4 1100
+5 0101 -3 1101
+6 0110 -2 1110
+7 0111 -1 1111
3/25/2023 72
3/25/2023 73
3/25/2023 74
Eg: Convert the given signed binary number to decimal
equivalent using Sign-magnitude form, 1’s complement form
and 2’s complement form.
010111 + 23 + 23 + 23
10111 -7 -8 -9
1101010 - 42 - 21 - 22
3/25/2023 75
Arithmetic Operations With Signed Numbers
Addition
The two numbers in an addition are the addend and the
augend. The result is the sum. There are four cases that
can occur when two signed binary numbers are added.
1. Both numbers positive
2. Positive number with magnitude larger than negative
number
3. Negative number with magnitude larger than positive
number
4. Both numbers negative
Take one case at a time using 8-bit signed numbers as
examples. The equivalent decimal numbers are shown
for reference.
3/25/2023 76
3/25/2023 77
In a computer, the negative numbers are stored in 2’s
complement form so, as you can see, the addition process is
very simple: Add the two numbers and discard any final carry
bit.
Overflow Condition
When two numbers are added and the number of bits
required to represent the sum exceeds the number of bits in
the two numbers, an overflow results as indicated by an
incorrect sign bit. An overflow can occur only when both
numbers are positive or both numbers are negative. If the
sign bit of the result is different than the sign bit of the
numbers that are added, overflow is indicated.
3/25/2023 78
In this example the sum of 183 requires eight magnitude bits.
Since there are seven magnitude bits in the numbers (one bit
is the sign), there is a carry into the sign bit which produces
the overflow indication.
3/25/2023 79
Subtraction
Subtraction is a special case of addition. For example,
subtracting +6 (the subtrahend) from +9 (the minuend)
is equivalent to adding -6 to +9. Basically, the
subtraction operation changes the sign of the
subtrahend and adds it to the minuend. The result of a
subtraction is called the difference. The sign of a
positive or negative binary number is changed by taking
its 2’s complement.
For example, when you take the 2’s complement of the
positive number 00000100 (+4), you get 11111100,
which is -4 as the following sum-of-weights evaluation
shows:
-128 + 64 + 32 + 16 + 8 + 4 = -4
3/25/2023 80
As another example, when you take the 2’s complement of
the negative number 11101101 (-19), you get 00010011,
which is +19 as the following sum-of-weights evaluation
shows:
16 + 2 + 1 = 19
3/25/2023 81
3/25/2023 82
P) Perform the subtraction with the following Unsigned binary
numbers using 1’s and 2’s complement of the subtrahend.
a) 11010-10000 b) 11010-1101 c) 1010100-1010100
3/25/2023 83
P) The binary numbers listed have a sign bit in the left most
position and if negative, numbers are in 2’s complement
form. Perform the arithmetic operations and verify the
answers.
a) 101011 + 111000 b) 001110 + 110010
Sol:
3/25/2023 84
c) 111001 - 001010 d) 101011 - 100110
3/25/2023 85
Multiplication
3/25/2023 86
3/25/2023 87
The partial products method is perhaps the more common one
because it reflects the way you multiply longhand. The
multiplicand is multiplied by each multiplier digit beginning
with the least significant digit. The result of the multiplication
of the multiplicand by a multiplier digit is called a partial
product. Each successive partial product is moved (shifted) one
place to the left and when all the partial products have been
produced, they are added to get the final product.
The sign of the product of a multiplication depends on the
signs of the multiplicand and the multiplier according to the
following two rules:
▪ If the signs are the same, the product is positive.
▪ If the signs are different, the product is negative.
3/25/2023 88
3/25/2023 89
3/25/2023 90
Division
The numbers in a division are the dividend, the divisor, and
the quotient. These are illustrated in the following standard
division format.
𝑫𝒊𝒗𝒊𝒅𝒆𝒏𝒅
= 𝑸𝒖𝒐𝒕𝒊𝒆𝒏𝒕
𝑫𝒊𝒗𝒊𝒔𝒐𝒓
The division operation in computers is accomplished using
subtraction. Since subtraction is done with an adder, division
can also be accomplished with an adder.
The result of a division is called the quotient; the quotient is
the number of times that the divisor will go into the dividend.
The sign of the quotient depends on the signs of the dividend
and the divisor according to the following two rules:
▪ If the signs are the same, the quotient is positive.
▪ If the signs are different, the quotient is negative.
3/25/2023 91
When two binary numbers are divided, both numbers must be
in true (uncomplemented) form. The basic steps in a division
process are as follows:
Step 1: Determine if the signs of the dividend and divisor are
the same or different. This determines what the sign of the
quotient will be. Initialize the quotient to zero.
Step 2: Subtract the divisor from the dividend using 2’s
complement addition to get the first partial remainder and add
1 to the quotient. If this partial remainder is positive, go to
step 3. If the partial remainder is zero or negative, the division
is complete.
Step 3: Subtract the divisor from the partial remainder and add
1 to the quotient. If the result is positive, repeat for the next
partial remainder. If the result is zero or negative, the division
is complete.
3/25/2023 92
Continue to subtract the divisor from the dividend and the
partial remainders until there is a zero or a negative result.
Count the number of times that the divisor is subtracted and
you have the quotient.
3/25/2023 93
3/25/2023 94
Hexadecimal Addition
3/25/2023 95
2. If the sum of these two digits is 𝟏𝟓𝟏𝟎 or less, bring
down the corresponding hexadecimal digit.
3. If the sum of these two digits is greater than 𝟏𝟓𝟏𝟎 ,
bring down the amount of the sum that exceeds 𝟏𝟔𝟏𝟎 and
carry a 1 to the next column.
3/25/2023 96
3/25/2023 97
Hexadecimal Subtraction
3/25/2023 98
Method 2: Subtract the hexadecimal number from the
maximum hexadecimal number and add 1.
3/25/2023 99
Method 3: Write the sequence of single hexadecimal
digits. Write the sequence in reverse below the forward
sequence. The 1’s complement of each hex digit is the
digit directly below it and add 1.
3/25/2023 100
3/25/2023 101
7’s Complement and 8’s Complements of Octal
Numbers:
Eg: Express 326 in 7’s and 8’s complement form.
Sol:
7’s Complement: 777
326
451
3/25/2023 102
15’s Complement and 16’s Complements of Hexa-
Decimal Numbers:
Eg: Express E8A, 1B06 in 15’s and 16’s complement form.
Sol:
15’s Complement: F F F FFFF
E8A 1B06
175 E4F9
16’s Complement: +1 +1
176 E4FA
3/25/2023 103