Number Systems and Binary Arithmetic: C H A P T e R
Number Systems and Binary Arithmetic: C H A P T e R
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
18 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
ack c u -tr a c k
c
c u -tr
h
a
p
Number Systems and t
Binary Arithmetic e
r 2
LEARNING
OBJECTIVES
After studying this chapter, the readers will be able to
∑ explain the number system used in computers ∑ subtract signed numbers in 1’s complement and 2’s
∑ learn about the digit symbols, base, and representation complement representation
forms of various number systems developed and used ∑ explain the technique of multiplication and division of
∑ explain the method of number system conversions binary numbers
∑ add and subtract unsigned binary numbers ∑ explain binary codes and their classification
∑ differentiate signed magnitude, 1’s complement, and
2’s complement representation of binary numbers
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 19
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
factor of 10 raised to the power of value equal to the position
2.2 Base of a Number System
of the digit symbol. For each column to the left, the value of
The base, or radix, of any number system is determined by the multiplier increases by 10 over the previous column on
the number of digit symbols in the system. For example, the right.
binary is a base-2 number system since it uses two symbols Let us consider the number 754 in the decimal number
and decimal is a base-10 system since it uses ten symbols. system.
In general, in any number system, a number N can be 7 . 10 2 + 5 . 101 + 4 . 10 0 = 700 + 50 + 4 = 754
represented by any one of the following forms:
(a) Positional notation form: Digit
Base
N = d n - 1 d n - 2 ... d1 d 0 ◊ d -1 d -2 ... d - m Position
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
20 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
2.4.2 Binary Number System [Base-2] 2.4.4 Hexadecimal Number System [Base-16]
The binary number system uses TWO symbols to represent The hexadecimal number system uses SIXTEEN symbols to
numerical values. These are 0 and 1 with 0 having the least represent numbers. The symbols are
value and 1 having the greatest value. Number representation 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F
in the binary system is similar to that in the decimal system, with 0 having the least value and F having the greatest value.
in which the digit on the extreme left represents the greatest Number representation in hexadecimal system is done in the
value and is called the most significant digit (MSD), whereas same way as in the decimal system, in which the symbol on
the digit on the extreme right is known as the least significant the extreme left represents the most significant digit.
digit (LSD). ∑ Each position to the left increases by a weight of 16. Thus,
∑ Each position to the left increases by a weight of 2. (i) F + 1 = 10 (F ‘i.e. 15’ plus one equals zero, carry one
or 10)
Example (ii)
2 1 0 Digit position (in decimal)
(i) It should be noted that 1 + 1 = 10 (one plus one equals zero, carry 2 A 616 Hexadecimal number
one or 10)
6 ¥ 160 = 6
(ii) 3 2 1 0 Digit position (in decimal)
1 0 1 12 Binary number 10 ¥ 16 =
1
160
1 ¥ 20 = 1 2 ¥ 16 =
2
512
1¥2 =1
2 67810
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 21
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Rule 2 The value of the largest digit symbol is one less discuss the way conversions from one number system to
than the base. other number systems are carried out.
Examples:
2.5.1 Working with Integer Numbers
Decimal system—largest digit = 10 – 1 = 9
Binary system—largest digit = 2 – 1 = 1 Conversion of a decimal number to its binary
Rule 3 Each position multiplies the value of the digit
equivalent
symbol by the base raised to the power of the value Method 1 Repeated-division-by-2 method
equal to the digit symbol position. 1. Divide the dividend, that is, the decimal number by two
Examples: and obtain the quotient and remainder.
Decimal system—consider the number 2. Divide the quotient by two and obtain the new quotient
125 = 1 × 102 + 2 × 101 + 5 × 100 and remainder.
Rule 4 A carry from one position to the next increases 3. Repeat step 2 until the quotient is equal to zero (0).
its weight base times. 4. The first remainder produced is the least significant bit
Examples: (LSB) in the binary number and the last remainder is
Decimal system—consider the number the most significant bit (MSB). Accordingly, the binary
number is then written (from left to right) with the MSB
5—5 = 5 × 100 or 5 ones.
occurring first (list the remainder values in reverse
Moving the number, one place, to the left, it becomes— order). This is the binary equivalent.
5 × 101 or 5 tens or 50.
Binary system—consider the number Example
0
1—1 = 1 × 2 or 1 one. Converting the decimal number 254 into its binary equivalent.
Moving the number, one place, to the left, it becomes— Divisor Dividend Quotient
1 × 21 or two 1’s or 10 2 254
Remainder
Till now the different number systems have been discussed. Example
But what happens when a number in one number system Converting the decimal number 247 into its binary equivalent.
representation needs to be represented in another form? So The largest power of 2 that is less than 247 is 27 = 128. Form the table
it is necessary to understand how numbers from one form with the weighting factor in the columns in the order shown, with 128 being the
may be represented in other forms. The following sections most significant weight. Put 1 in the digit position with weighting factor 128.
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
22 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 23
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Table 2.3 Binary equivalents for octal digits Example
Octal digit Equivalent binary number
Quotient Remainder
0 000 16 89066
1 001 16 5566 10 = A Equivalent hexadecimal
16 347 14 = E number
2 010 15BEA
16 21 11 = B
3 011
16 1 51 = 5
4 100
0 11 = 1
5 101
Remainder in
6 110 hexadecimal form
7 111
Starting with the last remainder, convert the remainders into
hexadecimal numbers:
Example 1 5 11 14 10 = 15BEA = the hexadecimal number.
Converting the octal number 236700321 to its equivalent binary number.
Conversion of a hexadecimal number to its
Octal number Equivalent binary number
decimal equivalent
2 010 To convert a hexadecimal to decimal, begin by multiplying
3 011 each of the hexadecimal digits by their positional weight
values as expressed in decimal. Then the resulting values are
6 110
added to obtain the value of the decimal number.
7 111
0 000 Example
Hexadecimal number
Conversion of a binary number to its equivalent
A 4 D 3 116
necessary to add zeros as the MSB, in order to complete a A ¥ 164 = 10 ¥ 65536 = 655360
grouping of three bits. Note that this does not change the 67512110
value of the binary number.
Final
Example Multiplier in Positional Multiplier
decimal
hexadecimal weight value in decimal
Converting (010111)2 to its equivalent octal number. (in decimal)
value
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
24 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Table 2.4 Number systems equivalency Example
Decimal Binary (Base-2) Hexadecimal Converting the binary number 1111011101101011011 to its equivalent
(Base-10) (Base-16) hexadecimal number.
0 0000 0 The conversion is done as follows:
A leading zero had to be added for the most significant group to have
1 0001 1
four bits.
2 0010 2 Binary Numbar 0111 1011 1011 0101 1011
3 0011 3 Equivalent hexadecimal 7 B B 5 B
4 0100 4 numbar
Example 001 1
010 2
Converting the hexadecimal number AF376 to its equivalent binary number.
111 7
Hexadecimal number A F 3 7 6
100 4
Equivalent binary number 1010 1111 0011 0111 0110
110 6
101 5
Conversion of a binary number to its hexadecimal
110 6
equivalent
100 4
Hexadecimal system works very much like the octal system,
000 0
except that each digit needs exactly four bits to represent it.
010 2
This means the binary number has to be divided into groups
of four digits, again starting from the digit at the extreme Therefore, we see that AF35D0216 = 12746564028
right. The equivalent hexadecimals for each set of four digits
are then written. For whole numbers, it may be necessary to Example
add zeroes as the MSB in order to complete a grouping of Converting the octal number 1273244 to its equivalent hexadecimal.
four bits. Note that this addition does not change the value of The given number is written by replacing the octal digits with equivalent
the binary number. three-bit binary numbers.
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 25
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
In groups of 3 bits Just as the decimal system with its ten digits is a base-
1 001 10 system, the binary number system with its two digits, 0
2 010 and 1, is a base-2 system. Table 2.6 shows the weighting for
4 111 the binary number system up to two decimal places after and
7 111 three places before the binary point (.) Note the similarity
3 011
with the decimal system.
2 010
Table 2.6 Binary weights
4 100
4 100
Weights 22 21 20 2–1 2–2
The binary number is regrouped as four-bit binary numbers that are
replaced with hexadecimal symbols. The least significant bit (LSB) is the rightmost binary
In groups of 4 bits Equivalent hexadecimal
digit, which has the lowest binary weight of a given number.
The most significant bit (MSB) is the leftmost binary digit,
0010 2
which has the highest binary weight of a given number.
1011 B
Counting in binary is similar to the decimal number system.
1111 F
The LSB begins with zero (0) and is incremented until the
0110 6
maximum digit value is reached. The adjacent bit positions
1010 A
are then filled appropriately as the iterative counting process
0100 4
continues.
Therefore, we see that 12732448 = 2BF6A416.
note
However, there are easier conversion methods. Some ways
∑ For conversion from any number base system to
to perform conversion between the bases are as follows. decimal use expanded notation.
Any base to decimal Use expanded notation. Write down ∑ For conversion from decimal number system to any
each digit as a product of a power of the base and add them base use the division method.
all. ∑ While converting octal number to hexadecimal number or
vice versa use binary as an intermediate form.
Decimal to any base Use the division method. Divide the
∑ It is important to note that many decimal fractions do not
decimal number repeatedly with the base, writing down the have an exact representation in binary.
remainder at each step. When the quotient becomes zero, the
string of remainders is the number in the new base.
Octal to hexadecimal or vice versa Use binary as an Conversion from decimal fractions to binary
intermediate form. When converting a fractional decimal value to binary, a
slightly different approach is needed. Instead of dividing
2.5.2 Working with Fractional Numbers
by 2, the decimal fraction is multiplied by 2. If the result is
One is familiar with the decimal (base-10) number system. greater than or equal to 1, then 1 is to be put as the quotient.
Each digit within any given decimal number is associated If the result is less than 1, then 0 is put as the quotient.
with a weight. Furthermore, the value of that number is the
sum of the digits after each has been multiplied by its weight. Example
To illustrate, let us consider Table 2.5 and assume that the
Converting (0.375)10 to binary.
number 654.52, written as (654.52)10 to specify base-10, is
0.375 × 2 = 0.750 0
being represented. Note that the digits range from 0 to 9.
0.750 × 2 = 1.500 1
0.500 × 2 = 1.000 1
Table 2.5 Decimal number system
done.
Hundreds Tens Units One- One- Note that the last operation is complete when the fraction part equals
tenth hundredth
zero. It is rarely possible to accurately represent a fractional value in binary.
Weights 102 101 100 10–1 10–2
The answer to this problem is: .011
Symbols 6 5 4 5 2
It is important to note that many decimal fractions do not have an exact
Total
Weighted representation in binary. This is illustrated in the following example.
600 50 4 0.5 0.02 654.52
value
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
26 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Example Table 2.7 Octal weights
Converting (0.29)10 to binary.
Weights 82 81 80 8–1 8–2
0.29 × 2 = 0.58 0
0.58 × 2 = 1.16 1
0.16 × 2 = 0.32 0
To express a given octal number as its decimal equivalent,
0.32 × 2 = 0.64 0 each bit is multiplied by its associated weight and the
0.64 × 2 = 1.28 1 summation of these gives the decimal number.
0.28 × 2 = 0.56 0
Example
0.56 × 2 = 1.12 1
0.12 × 2 = 0.24 0 Converting (237.04)8 to a decimal number.
0.24 × 2 = 0.48 0 2 3 7. 0 4
0.48 × 2 = 0.96 0
4 ¥ 8–2 = 0.0625
0.96 × 2 = 1.92 1
0¥8 =–1
0
0.92 × 2 = 1.84 1
0.84 × 2 = 1.68 1 7¥8 =0
7
0.68 × 2 = 1.36 1 3¥8 =1
24
0.36 × 2 = 0.72 0 2¥8 =2
128
0.72 × 2 = 1.44 1
159.062510
The decimal point is at the top so the conversion of .29 to binary upto Multiplier Weight
16-bits of approximation is:
.0100101000111101
Conversion from decimal fractions to octal
The whole number is ignored before multiplying again for the next digit.
The techniques used to convert decimal fractions to octal
While using a calculator, just enter the decimal fraction value and multiply
by 2. Writing a computer program to perform these operations is easy using
are similar to the methods demonstrated previously to
this technique. convert decimal fractions to binary numbers. The repeated-
multiplication-by-8 method is used. In the multiplication-
Conversion from binary fraction to decimal by-8 method, the fraction is repeatedly multiplied by eight,
To express the value of a given fractional binary number and the integer number is recorded until the fraction part is
in equivalent decimal value, each bit is multiplied by its zero. The first integer produced is the MSD, while the last
associated weight and the summation of these gives the integer is the LSD. Remember that the octal point precedes
desired decimal number. the MSD. To illustrate, consider the following conversion.
Example Example
Converting (0.1011)2 to a decimal number. Converting (0.3125)10 to an octal number.
0. 1 0 1 1 0.3125 ¥ 8 = 2.5000 2
1 ¥ 2– 4 = 0.0625
1 ¥ 2–3 = 0.125 0.5 ¥ 8 = 4.0 4
0¥2 =–2
0
0.248
1¥2 =–1
0.5
0.687510 Thus, (0.3125)10 = (0.24)8
Multiplier Weight
Conversion from octal fraction to binary
Conversion from octal fraction to decimal The primary application of octal numbers is representing
binary numbers, as it is easier to handle large numbers in
Just as the decimal system with its ten digit symbols is a
octal form than in binary form. Because each octal digit can
number system with base 10, the octal number system with
be represented by a three-bit binary number (see Table 2.8),
its 8 digit symbols, ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’ and ‘7’, has
eight as its base. Table 2.7 shows the weights for an octal it is very easy to convert from octal to binary. Simply replace
number that has three decimal places before and two digit each octal digit with the appropriate three-bit binary number
places after the octal point (.). as indicated in the following examples.
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 27
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Table 2.8 Octal and binary numbers Table 2.9 shows the weight for the hexadecimal number
system up to three digit places before and two places after the
Octal digit Binary digit hexadecimal point. Based on the trend in previous number
0 000 systems, the methods used to convert hexadecimal to decimal
1 001 and vice versa should be similar.
2 010 Table 2.9 Hexadecimal weights
3 011
Weights 162 161 160 16–1 16–2
4 100
5 101
Table 2.10 lists the equivalent decimal, binary, and
6 110 hexadecimal representations for the decimal numbers ranging
7 111 from 0 to 15. Each hexadecimal number can be represented
as a four-digit binary number.
Example
Table 2.10 Number systems equivalency table
(a) Converting 138 to equivalent binary number.
Decimal Binary Hexadecimal
Octal number 1 3
Binary number 001 011 0 0000 0
Example
Octal number 2 . 7
Converting (37.12)16 to binary number.
Thus, (010.111)2 = (2.7)8 Hexadecimal number 3 7 . 1 2
Binary number 0011 0111 . 0001 0010
(b) Converting (0.110101)2 to octal
Binary 0 0 0 . 1 1 0 1 0 1
Conversion from binary fraction to hexadecimal
number Converting from binary to hexadecimal is also a simple
process. Arrange the binary digits into groups of four
Octal 0 . 6 5
number starting from the binary point and convert each group into its
appropriate hexadecimal digit symbol. For whole numbers,
Thus, (0.110101)2 = (0.65)8 it may be necessary to add a zero with the MSD in order
to form a grouping of four bits. Note that this addition does
Hexadecimal number conversion not change the value of the binary number. Similarly, while
Just like the octal number system, the hexadecimal number representing fractions, it may be necessary to add a trailing
system provides a convenient way to express binary numbers. zero in the LSD in order to form a grouping of four bits.
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
28 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Example the next column. In the decimal system, because 10-digit
Converting (0.00111111)2 to hexadecimal symbols exist, a carry does not get generated until the sum of
Binary number 0 . 0011 1111 two digits is greater than or equal to 10 (e.g., 5 + 7 = 12).
Hexadecimal number 0 . 3 F
Table 2.11 Rules for binary addition
Thus, (0.00111111)2 = (0.3F)16
Rule 1 Rule 2 Rule 3 Rule 4
Check Your Progress 0 0 1 1
Four basic rules are needed to perform binary addition. Table 2. The next column is added. 1 plus 1 equals 102, so a 1 is carried to
2.11 lists these rules. The first three rules are quite simple the next column and the 0 is written under this column.
and there is no difference between these binary rules and 1 0 Carry
the corresponding decimal rules. The fourth rule, however, 0 1 1 1 1
is different from the decimal rule. When two 1’s are added + 0 0 1 1 0
together in binary, a carry gets generated which is placed in
0 1 Result
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 29
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
3. Notice that the third column now contains three 1’s. Adding the first 1. To compute the first column, a 1 is borrowed from
two 1’s gives 102. Adding this sum to the remaining 1 gives a total of the next column. Recall that two 1’s generate a carry
112, so a 1 is carried to the next column and a 1 is written under this in addition. If this process is reversed, a 1 can be
column. borrowed from the second column and two 1’s in the
1 1 0 Carry first column can be marked.
0 1 1 1 1 Second column First column
+ 0 0 1 1 0 10 Minuend
–1 Subtrahend
1 0 1 Result
2. Following a borrow from the 1¸
4. The two ones in the fourth column total 102, so a 1 is carried to the
second column, the 1 is crossed out ˝ Borrow
final column, and a 0 is written below this column. 01˛
and a 0 is written above it to show
1 1 1 0 Carry that this column is now empty. 10 Minuend
0 1 1 1 1 The 1 from the second column is -1 Subtrahend
+ 0 0 1 1 0 now represented by the two 1’s in
0 1 0 1 Result the first column.
5. Finally, the carry from the previous column plus the two 0’s from this
3. Following a borrow from the 1¸
column add to 1.
second column, the 1 is crossed out ˝ Borrow
01˛
and a 0 is written above it to show
1 1 1 0 Carry
that this column is now empty. 10 Minuend
0 1 1 1 1
The 1 from the second column is -1 Subtrahend
+ 0 0 1 1 0
now represented by the two 1’s in 1 Re sult
1 0 1 0 1 Result
the first column.
6. This gives a final answer of 101012.
4. Note that the first column of the 10 Minuend
1 1 1 0 Carry answer is identical to Rule 4. -1 Subtrahend
0 1 1 1 1 1 Re sult
Since a 1 was borrowed from the
+ 0 0 1 1 0
next column, the second column
1 0 1 0 1 Result becomes 0.
The rules of subtraction can be applied to solve larger
2.6.2 Subtraction subtraction problems in binary arithmetic. The example
For subtraction in the decimal system, normally the borrow below demonstrates how to subtract binary number 11102
method is used. Consider the example on the right. Here a from 101012.
10 is borrowed from the tens column in order to complete
Example
the subtraction in the ones column. Moving 10 to the ones
column and subtracting 6 yields 4. The remaining 20 from Subtract 11102 from 101012.
the tens column is taken and 2 is written in the tens column Solution:
to get the result of 2410. 1. Consider subtraction of the extreme right 10101 Minuend
The borrow method can also be used to do binary column. 1 minus 0 equals 1. - 01110 Subtrahend
subtraction. The basic rules for binary subtraction are listed
in Table 3.2. 1 Result
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
30 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
4. Now, subtraction of the next column is called the signed magnitude representation. Note that this
1 1¸
carried out. Since a 1 was borrowed from ˝ Borrow is very similar to adding a minus sign in decimal.
0101 ˛ Still one small problem remains with the representation. It
this column, the subtraction is 0 minus
1 and a borrow has to be made again. 10 101Minuend is necessary to specify how many bits are there in a number
However, there is no borrow in the next - 01110 Subtrahend to know which bit is representing the sign. Let us convert
column. So first, a borrow from the most 11 Result the decimal numbers –510 and –110 to binary using signed
significant column must be made. magnitude representation. For these numbers, four bits will
be enough to represent both.
5. Then borrow a 1 from the fourth column to
1 ¸ 1. 5 and 1 are converted to binary. 101 (5)
the current column. Ô
111 ˝ Borrow 1 (1)
Ô 2. Now a positive sign bit is added to each
0 10 1 ˛ 0101 (5)
10 101 Minuend one. Notice that ‘1’ is padded with zeros 0001 (1)
so that it has four bits.
- 01110 Subtrahend sign bit
11 Result
3. To make the binary numbers negative, 1101 (–5)
6. Now the current column can be
1 ¸ simply change the sign bit from 0 to 1. 1001 (–1)
subtracted. A 1 is taken away from the Ô
111 ˝ Borrow One has to be sure not to mistake the number 11012 for
group of two 1’s. This leaves a single 1
Ô
which is written below the column. 0 10 1 ˛ 1310. Since a four-bit signed magnitude representation is
10 101 Minuend used, the first bit is the sign bit and the remaining three bits
are for the magnitude (absolute value) of the number.
-01110 Subtrahend
Therefore, the sign and magnitude of the integer are
111 Result
represented separately. A negative integer, for example, is
7. In the fourth column, a 1 is subtracted
1 ¸ represented by a 1 in the leftmost bit and the absolute value
from a 1 for a result of 0. Ô in the remaining bits. The range of integers that can be stored
111 ˝ Borrow
Ô in signed magnitude is –2n–1 + 1 to +2n–1 – 1, where n is the
0 10 1 ˛ number of bits in the signed magnitude number.
10 101 Minuend While representing negative numbers with signed
-01110 Subtrahend magnitude is simple, performing arithmetic with signed
0111 Result magnitude is difficult. Consider the subtraction problem 3010
– 610. This can be converted to an equivalent addition problem
8. The most significant column contains all
1 ¸ by changing 610 to –610. Now, the problem may be restated as
zeros, so 0 is written below it. Hence, the Ô
111 ˝ Borrow 3010 + (–610) = 2410. Something similar can be done in binary
result is 001112.
Ô by representing negative numbers as complements. Two ways
0 10 1 ˛
of representing signed numbers using complements will be
10 101 Minuend discussed: 1’s complement and 2’s complement in the next
-01110 Subtrahend section.
00111 Result
note
2.6.3 Binary ∑ When a single bit number 1 is added with another single
So far in the study of binary arithmetic, only positive bit number 1 the sum bit is 0 and the carry bit is 1.
numbers have been considered. Now, a way is needed to ∑ When a single bit number 1 is subtracted from a single
represent numbers such as –3210. When computations are bit number 0 the difference bit is 1 and the borrow bit is
1.
done in decimal, a minus sign precedes a number to make it
negative. Since computers can only work with 1’s and 0’s, it ∑ In the signed magnitude representation of binary
numbers, the integer is represented by a sign bit in
is necessary to modify this approach slightly.
the most significant bit position followed by the binary
One solution is to add an extra binary digit to the left of the representation of the magnitude. For a negative integer,
binary number to indicate whether the number is positive or the msb is 1 whereas for a positive integer the msb is 0.
negative. In computer terminology, this digit is called a sign ∑ Subtraction of integers in signed 2’s complement
bit. Remember that a ‘bit’ is simply another name for a binary representation produces results in true signed magnitude
digit. When a number is positive, the sign bit is zero, and when form.
the number is negative, the sign bit is one. This approach is
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 31
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
1’s Complement 3. Remove the final carry (overflow bit) and add it to the
A signed number with 1’s complement is represented by result, i.e., if the sum exceeds n bits, add the extra bit to
changing all the bits that are 1 to 0 and all the bits that are 0 to 1. the result. This bit is called the end-around carry.
Reversing the digits in this way is also called complementing
Example
a number, as illustrated by the examples below.
Subtract 110 from 710 using 1’s complement.
Example Solution:
Obtaining the 1’s complement of (i) 10001 and (ii) 101001. Now, 110 = 00012 and 710 = 01112
Solution: 1. The problem is stated with sign bit
the numbers in binary.
Number 1’s Complement 0111 (7) Minuend
10001 01110 – 0001 – (1) Subtrahend
sign bit
2’s Complement
4. Notice that the addition 0101
The 2’s complement of a binary number is obtained by adding
generated an overflow bit. +1
1 to the 1’s complement representation as illustrated by the 0110 (6) Sum
Whenever an overflow bit Overflow bit
examples below.
occurs in such a method,
sign bit
Example add the bit to the sum to get
the correct answer. If there
Obtain 2’s complement of (i) 10001 and (ii) 101001.
is no overflow bit, leave the
Solution:
sum as it is.
Number 1’s Complement 2’s Complement 5. This gives a final answer of 0111 (7)
10001 01110 01111 01102 (or 610). – 0001 – (1)
True
0110 (6) magnitude
101001 010110 010111
sign bit
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
32 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 33
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
2. Convert 00012 to its negative 0001 1110 1. Determine the 2’s complement of the larger number.
equivalent in 2’s complement. +1 2. Add 2’s complement to the smaller number.
2’s complement 1111
To do this change all the 1’s form 3. There is no carry from the leftmost column. The result is in 2’s
to 0’s and 0’s to 1’s and add complement form and is negative.
one to the number. Notice
4. Take the 2’s complement of the result to get the final answer.
that the most significant digit
is now 1 since the number is Example
negative. Subtracting 11012(1310) from 10012(910) using 2’s complement.
3. Add the negative value 11112 sign bit Solution:
to 01112. This gives the sum
0111 (7) 1. State the problem. 01001 (7)
101102. – 01101 – (13)
+ 1111 + (–1)
10110 (?)
overflow bit 2. Convert 11012 to its negative 01101 10011
equivalent in 2’s complement. sign bit
4. Notice that the addition 0111 (7) 2’s complement
caused an overflow bit. – 1111 – (1)
3. Next, add 100112 to 010012. 01001
0110 (6)
Whenever an overflow bit in Result in true The sign bit being 1, the result is + 10011
11100
2’s complement occurs, it is sign bit magnitude negative and the magnitude is in 2’s
discarded. Hence, the final 2’s complement. sign bit complement
result is 01102 (or 610).
4. Take the 2’s complement of the – 01102
sum to get –01002–01002, i.e.,
Example –410.
Subtracting the binary number 10012(910) from 11012(1310) by converting
Points to remember: The steps for subtracting y from x, with an n-bit 1’s
10012 to its negative equivalent in 2’s complement and adding this value
complement representation are as follows.
to 11012.
1. Negate y using 1’s complement, i.e., reverse all the bits in y to form
Solution:
–y.
1. State the problem. Magnitude part
2. Add –y, in 1’s complement form, and x.
01101 (13)
Minuend 3. If the sum exceeds n bits, add the extra bit to the result.
– 01001 – (9) Subtrahend
4. If the sum does not exceed n bits, leave the result as it is.
The steps for subtracting y from x with an n-bit 2’s complement
2. Convert 10012 to its negative 1’s complement form
representation are as follows.
equivalent in 2’s complement.
To do this, change all 1’s to 0’s 01001 10110 1. Negate y using 2’s complement, i.e., reverse all the bits in y and add
and vice versa. 1 to form –y.
sign bit
2. Add –y in 2’s complement form, and x.
3. Add 1 to the number to obtain 10110 3. If the sum exceeds n bits, discard the extra bit.
the negative equivalent. Notice +1 (–9) Subtrahend in Notice that with 1’s complement, it is necessary to check for an overflow
that the most significant digit
10111 2’s complement bit each time subtraction is performed. If the result has an overflow bit, the
is now 1 since the number is extra bit is added to the result to obtain the correct result. However, with 2’s
negative. complement, this extra bit is ignored. No other computations are required
to find the correct result.
4. Add the negative value 101112 01101 (13)
to 011012. This gives the sum – 10111 + (–9)
2.6.4 Multiplication
1 00100 (?)
1001002. However, the leftmost
Binary multiplication uses the same techniques as decimal
bit, which is the overflow bit, is Overflow bit sign bit
multiplication. In fact, binary multiplication is much easier
discarded.
because each multiplying digit is either zero or one. Consider
5. Hence, the final result is 001002 01101 (13)
the simple example of multiplying 1102 by 102. This example
(or 4). + 10111 + (–9)
00100 (4) is used to review some terminology and illustrate the rules for
binary multiplication.
sign bit Ture magnitude
For subtracting a larger number from a smaller number, the 2’s Example
complement method is implemented as follows. Multiplying 1102 by 102.
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
34 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Solution: 6. Notice that the third digit in the 1111
1. Note that 1102 is the multiplicand and 110 Multiplicand
multiplier is 0. Since any number ¥ 1011
102 is the multiplier. ¥ 10 multiplier multiplied by zero is zero, place a row 1111
1111 Third partial
of zeroes as the third partial product 0000 product
2. Begin by multiplying 1102 by the 110 as shown.
rightmost digit of the multiplier that is ¥ 10
7. Now, multiply with the most significant 1111
0. Any number times zero is zero, so 000 ¥
digit of the multiplier. Since this is the 1011
just zeroes are written below. 1111
fourth multiplication, the fourth partial 1111
3. Multiply the multiplicand by the next 110 product is placed below the third 0000
digit of the multiplier, which is 1. ¥ 10 partial product and shifted by one
000 Partial product
To perform this multiplication, just 110 Partial product column to the left with respect to the
copy the multiplicand and shift it latter.
one column to the left as is done in
8. The most significant digit of 1111
decimal multiplication. ¥ 1011
the multiplier is 1, so the fourth
4. Add the partial products. Hence, the 110
partial product is the same as the 1111
¥ 10 1111
product of the multiplication is 11002. multiplicand. This partial product is 0000 Fourth partial
000
placed as shown. 1111 product
110
1100 Result 9. Now, all the partial products are 1111
added to get the final value of the ¥ 1011
When performing binary multiplication, remember the following rules.
1111
multiplication product as 101001012.
1. Copy the multiplicand when the multiplier digit is 1. Otherwise, write 1111
0000
a row of zeros.
1111
2. Shift the results one column to the left for a new multiplier digit. 10100101
3. Add the results using binary addition to find the product.
2.6.5 Division
Example
Division of binary numbers uses the same technique as
Multiplying 11112 by 10112. division in the decimal system. It will be helpful to review
Solution: some of the basic terms of division. Consider the example
The binary numbers 11112 and 10112 can be multiplied using the same given below.
rules as decimal multiplication.
1. Multiply the multiplicand by the 1111 Example
Multiplicand
extreme right digit of the multiplier. ¥ 1011 multiplier Dividing 3310 by 610.
Solution:
2. Since this number is 1 and any 1111
1. In this problem, 6 is the divisor, 33 is the dividend, 5
number multiplied by 1 equals itself, ¥ 1011 First partial
6 33
1111 product 5 is the quotient, and 3 is the remainder. The same
simply record the multiplicand below. 30
terms describe binary division. 3
3. Now multiply the multiplicand by the
next digit in the multiplier. Since this is
Example
the second multiplication, the second
partial product obtained would be 112/102 or 310/210.
placed below the first and shifted one Solution:
column to the left. Here, 102 is the divisor and 112 is the dividend. The steps that follow
show how to find the quotient—1.12.
4. The second digit in the multiplier is 1 1111
so the second partial product, which ¥ 1011 1. Find the smallest part of the dividend that is greater 10 11
1111
is same as the multiplicand, is placed 1111
Second partial than or equal to the divisor. Since the divisor has
product
as shown. two digits, start by checking the first two digits of the
5. Next, multiply by the third digit of 1111 dividend.
the multiplier. Since this is the third ¥ 1011
1111
multiplication, the third partial product 1111 2. 11 is greater than 10. Thus a 1 is written as the 1
is placed below the second partial quotient, the divisor is written below the dividend, 10 11
10
product and shifted to the left by one and subtraction is carried out. 1
column with respect to the latter.
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 35
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
3. Since there are no more digits in the dividend, but 1. 7. Note that after considering all the digits of the 101.
there still is a remainder, therefore the answer must 10 11.0 dividend a remainder still exists. This means that 110 100001.0
10 110
include a fraction. To complete the computation, it is 1 the result will include a fraction. To progress with 1001
necessary to mark the radix point and append a zero the division, it is necessary to mark the radix point 110
11
to the dividend. and append a zero to the dividend.
4. Bring down the extra zero and write it beside the 1. 8. Now bring down the extra zero and compare the 101.1
remainder. Then check to see if this new number is 10 11.0 remainder with the divisor. Notice that the radix 110 100001.0
10 110
greater than or equal to the divisor. Notice that the 10 point is ignored in the comparison. 1102 is equal to 1001
radix point is ignored in the comparison. 1102 so write another 1 in the quotient and subtract. 110
110
This completes the division because no more digits 110
5. 10 equals the divisor 10, so write a 1 in the quotient, 1. . exist in the dividend and there is no remainder. 0
copy the divisor below the dividend, and subtract. 10 11.0
10
This completes the division because there are no 10
more digits in the dividend and no remainder. 10 note
0
∑ Multiplication and division of binary numbers uses the
When doing binary division, some important rules need to be same rules as the decimal numbers.
remembered. ∑ Some fractions do not have an exact representation in
(a) When the remainder is greater than or equal to the divisor, write binary, so not all division computations will terminate.
a 1 in the quotient and subtract.
(b) When the remainder is less than the divisor, write a 0 in the
quotient and add another digit from the dividend.
Check Your Progress
(c) If all the digits of the dividend have been considered and there
is still a remainder, mark a radix point in the dividend and 1. The 2’s complement of the number 1101101 is
append a zero. Remember that some fractions do not have an (a) 0101110 (b) 0111110
exact representation in binary, so not all division problems will
(c) 0110010 (d) 0010011
terminate.
Answer: (d)
Example
2. –8 is equal to signed binary number
Dividing 1000012 by 1102 using the same technique used in long division (a) 10001000 (b) 00001000
in the decimal system.
Solution:
(c) 10000000 (d) 11000000
Answer: (a)
1. Find the smallest part of the dividend that is greater 110 100001
than the divisor 1102. Since the divisor has three 3. When signed numbers are used in binary arithmetic,
digits, begin by examining the first three digits of then which one of the following notations would have
the dividend. 1002 is less than 1102 so another digit unique representation for zero.
from the dividend must be added. (a) Sign-magnitude. (b) 1’s complement.
2. Try the first four digits of the dividend. Since 10002 is 110 100001 (c) 2’s complement. (d) 9’s complement
greater than 1102, the division is possible.
Answer: (a)
3. 1102 divides 10002 once, so write 1 as the first digit 1.
of the quotient, copy the divisor below the dividend, 110 100001 4. The result of adding hexadecimal number A6 to 3A is
110
and subtract using the borrow method. (a) DD (b) E0
10
4. Now bring down the next digit of the dividend and (c) F0 (d) EF
write it beside the remainder. Then check to see Answer: (b)
if this new number is greater than or equal to the 5. Perform 2’s complement subtraction of (7)10 – (11)10
divisor.
Answer: (4)10 or (11111100) in signed 2’ s complement
5. 1002 is less than 1102 so, write a 0 in the quotient
form.
and add another digit from the dividend to the
reminder. 6. Perform the following subtraction using 2’s complement
method: 0011.1001 – 0001.1110
6. 10012 is greater than 1102, so write a 1 in the 101
quotient and subtract 1102 from 10012. 110 100001 Answer: 0001.1011 or + 1.68625
110
1001 7. Divide (101110)2 by (101)2
110
Answer: Quotient = (1001)2 and Remainder = 0012
11
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
36 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 37
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Self-complementing code A code is called self-comple- 9 1001 1101
menting if the code word of the 9’s complement of N, i.e. 10 1010 1111
(9-N), can be obtained from the code word of N by inter- 11 1011 1110
changing all the 1’s and 0’s. The 9’s complement of 1 is 8. In 12 1100 1010
the (6, 4, 2, –3) code, decimal 1 is represented by 0101, while 13 1101 1011
decimal 8 is represented by 1010, which is the 1’s comple- 14 1110 1001
ment of 0101.The codes (2, 4, 2, 1), (5, 2, 1, 1), (4, 3, 1, 1), 15 1111 1000
and (3, 3, 2, 1) are the four positively weighted self-com-
plementing codes. There exist 13 negatively and positively The Excess-3 code is formed by adding 0011 to each code
weighted self-complementing codes like (8, 4, –2, –1) and (6, word of (8, 4, 2, 1) code or BCD. It is a self-complementing
4, 2, –3). The necessary condition for a weighted code to be code.
self-complementing is that the sum of the weights should be The Gray code is a cyclic code. Cyclic code is one in
equal to nine. which successive code words differ in only one digit. Such
codes are also known as unit distance codes.
Table 2.14 Excess-3 code
2.7.2 Alphanumeric Codes
Decimal number 8 4 2 1 code Excess-3 code
Digital computers are capable of handling bits. Keyboards
0 0000 0011
and printers, for example, are devices for transmitting and
1 0001 0100 receiving data to and from computers, respectively. The user
2 0010 0101 inputs data in the form of symbols representing alphabets,
3 0011 0110 numbers, and special characters. These symbols must be
represented by some code formed by a sequence of binary
4 0100 0111
digits for the digital computer to process. Similarly, a bit code
5 0101 1000 is sent by the computer to an output device, such as a printer,
6 0110 1001 which must depict alphabetic, numeric, or special character
information using the symbols.
7 0111 1010
There are several alphanumeric codes but two, ASCII and
8 1000 1011 EBCDIC, are normally used. The ASCII code, known as the
9 1001 1100 American Standard Code for Information Interchange, is
used widely. This is a seven-bit code and hence it can form
Sequential code A sequential code is one in which each
27 (128) bit patterns thereby having an ability to encode 128
of its subsequent code words is one binary number greater
symbols. Table 2.16 shows the ASCII code representing
than the preceding code word. The BCD code (8, 4, 2, 1) is a
capital letters/lowercase alphabets, decimal numbers,
sequential code. In most cases BCD code means the (8, 4, 2,
and special characters. Since the characters are assigned
1) code shown in Table 3.3.
in ascending binary numbers, it is convenient for digital
Non-weighted codes computers to convert from and to alphanumeric symbols.
Codes that do not obey the position-weighting principle are The standard ASCII code defines 128 character codes
called non-weighted codes. There are many non-weighted (from 0 to 127), of which the first 32 are control codes
binary codes. Two of these are the Excess-3, or XS-3, and (non-printable) and the other 96 are characters that can be
Gray Code. These are depicted in Tables 2.14 and 2.15. represented. The above table is organized to easily read the
ASCII code in hexadecimal form: row numbers represent the
Table 2.15 Gray code lower significant digit and the column numbers represent the
Decimal number Binary code Gray code most significant digit. For example, character A is located at
b3, b2, b1, b0 g3, g2, g1, g0 row four column one. Thus the ASCII code for character A is
0 0000 0000 represented in hexadecimal as 0x41, which in decimal is 65.
1 0001 0001 In addition to the 128 standard ASCII codes, there are
other 128 that are known as extended ASCII, and these are
2 0010 0011
platform-dependent. So, there is more than one extended
3 0011 0010
4 0100 0110
ASCII character set.
5 0101 0111 The two most used extended ASCII character sets are OEM,
which comes from the default character set incorporated in
6 0110 0101
the IBM PC, and ANSI extend ASCII, which is used by the
7 0111 0100
8 1000 1100
present operating systems.
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
38 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Table 2.16 ASCII code
Hex
L
S 0 1 2 3 4 5 6 7 8 9 A B C D E F
D
MSD
0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI
1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
2 SP ! “ # $ % & ‘ ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ^ _
6 ‘ a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ~ DEL
The OEM character set is included in the majority of ANSI Extended ASCII (Windows)
PC compatibles loaded with any operating system or msdos
system. It includes diverse symbols, some marked characters
and pieces to represent panels. However, it is usually redefined
according to regional configurations to incorporate particular
symbols in many countries.
OEM Extended ASCII
note
∑ Numeric codes represent numeric data with a series
of 0’s and 1’s. Among the various available codes, the
binary, hexadecimal and BCD codes are used mostly.
∑ Symbols representing capital letters/lowercase
alphabets, decimal numbers, and special characters,
The ANSI character set is a standard that is incorporated which are termed as alphanumeric characters, are also
represented by alphanumeric numeric codes formed
in systems such as Windows, some unix platforms, and many
with a combination of 1s and 0s. The ASCII code is the
applications. It includes many local symbols and marked most widely used code used to represent alphanumeric
letters so that it can be used without being redefined for other symbols.
languages.
Summary
A system in which quantities are represented by symbols bearing values Addition and subtraction of unsigned binary numbers are similar to
is called a number system. The base of a number system has a value the arithmetic rules followed for decimal numbers with the exception that
equal to the number of representation symbols the system has. A number the base here is 2. Signed magnitude representation of binary numbers
in a number system, in general, can be represented by any one of the consists of using a 0 for a positive number or a 1 for a negative number
following forms: (a) positional notation form, (b) polynomial form, and (c) in the most significant digit position of the number. Using 1’s and 2’s
compact form. The number systems that are used in computers are binary,
complement representation, the signed binary number can be subtracted
octal, and hexadecimal, whereas the decimal system is used by humans.
to obtain results correctly.
Conversion of binary numbers to decimal numbers, and vice versa, uses
the base of the binary number position of the digit. Conversion of binary to There are different classifications of binary codes used in computers.
octal and vice versa, binary to hexadecimal and vice versa, and all other These are numeric codes, alphanumeric codes, error-detecting codes, and
conversions between different number systems is possible. error-correcting codes.
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 39
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
Key Terms
Symbol It is any graphic character. Signed number A binary number in which the most significant bit rep-
Number system It is a set of symbols that represents a set of quantita- resents the sign of the number and the rest the magnitude of the number.
tive values. 1’s complement A number system that was used in some comput-
Base It represents the number of digit symbols in a number system. ers to represent negative numbers. To form 1s complement of a number,
each bit of the number is inverted which means zeros are replaced with
Radix It represents the number of digit symbols in a number system.
ones and ones with zero.
Decimal number system It is a number system that has ten symbols
2’s complement A number formed by adding 1 to the 1’s compliment
0,1,………..,9 which represents values.
of a number. The 2’s complement representation has become the stan-
Binary number system It is a number system that uses two symbols 0 dard method of storing signed binary integers. It allows the representation
and 1 to represent zero and one respectively. of an n-bit number in the range – 2n to 2n-1, and has the significant
Octal number system It is a number system that has eight symbols advantage of only having one encoding for 0.
0,1,………..,7 which represents values zero to seven respectively. BCD number Binary Coded Decimal (BCD) number is a number in
Hexadecimal number system a number system that has eight symbols which each of the digits of an unsigned decimal number is represented by
0,1,………..,F which represents values zero to sixteen respectively. the corresponding 4-bit binary equivalents.
Bit It is a binary digit. ASCII code American Standard Code for Information Interchange is a
Carry In a number system, when the result of addition of two single digit 7-bit binary code formed to represent decimal numbers 0 to 9, alphabetic
numbers is greater than the largest representable number symbol, a characters a to b( also A TO B), and special characters like ;, :, NUL, etc.
carry is said to be generated. This carry is placed in the next left column. for handling these characters in the digital computer and to also use this
binary code for exchanging data between digital computers connected in
Borrow In a number system, when a larger single digit number is sub-
a networked environment.
tracted from a smaller single digit, a borrow is generated.
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
40 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
also mathematical problems which included integro-differential equations, 7. Where is the Gray Code used?
etc. But with the availability of electronic devices and application of Boolean Answer:
logic concepts digital computers were developed that execute jobs at much
The gray code was primarily developed to prevent spurious output from
high speeds, consume less power, occupy much less space, weigh many
electromechanical switches. It is widely used in digital communications
times less, work reliably with very less maintenance effort and are easy to
to facilitate error correction. In position encoders, gray codes are used
operate. As a consequence digital computers, that employed electronic
in preference to straightforward binary encoding.
devices and applied Boolean logic concepts, outperformed all earlier
8. How important is signed magnitude representation of binary
models of computers. And because the digital computers use Boolean
numbers in digital computers?
logic concepts, binary numbers are obviously used in digital computers.
Answer:
4. Where is the octal number representation used?
Normally, a “ – “ symbol is placed before a number to indicate the negative
Answer:
nature of the number. On the other hand, a positive number is indicated
The octal number representation is used to represent large binary numbers
by putting “ + ” symbol or simply a blank before the number. But in a digital
in a shorter form. This simplifies the manual handling of binary numbers
computer, these graphic symbols, “ – “ and “ + ”, cannot be used directly.
while working with digital computers. For example, a binary number
All numbers and symbols are represented by a combination of “ 0s ” and ”
“1011001110010110 ” in octal number representation is “ 131626 ”, which
1s ”. Hence, the positive symbol, “ + ”, is represented by a “ 0 ” while the
contains 6 digits instead of 16 in the binary form.
negative symbol, “ – “ , is represented by a “ 1 ”. The sign bit , a “ 0 ” or a
5. Where is the hexadecimal number representation used? “ 1 ”, occupies the most significant digit position of a number represented in
Answer: binary. Therefore in an eight bit number, the most significant bit is a sign bit
The hexadecimal number representation, like the octal number while the rest of the seven bits represent the magnitude or value. Such a
representation, is a short-cut way to represent large binary numbers. Hence representation is essential for the logic circuits, within the digital computer,
a binary number “1011001110010110” becomes B396 in hexadecimal to suitably carry out arithmetic operations.
number representation. From the (above example) it is evident that for the 9. Why is 2’s complement representation preferred over 1’s
human computer user it is easier to handle the hexadecimal number than complement representation in binary arithmetic?
the big binary number shown. Answer:
6. How is the BCD representation useful? In 1’s complement representation, the carry, that occurs while adding
Answer: the signed magnitude numbers, is added to the least significant bit of the
Human beings are accustomed to use the decimal number system. result to obtain the proper result. This imposes an extra burden on the
Hence an output from the computer or computer based system, in computer by way of providing additional logic circuitry to form the final
decimal number form is more acceptable than in binary or hexadecimal result. In 2’s compliment representation, the carry that occurs while
or octal number form. To achieve this, the Binary Coded Decimal adding the signed magnitude numbers, is discarded to obtain the result in
number representation true magnitude form. Therefore, the extra burden of adding the carry bit to
has been made. obtain the final result is avoided in 2’s complement representation. Hence,
2’s complement representation is preferred.
exercises
1. Convert the following. 2. Convert the following decimal numbers to equivalent binary numbers.
(i) 01102 = 10 (i) 702 (ii) 134
(ii) 01102 = 8 (iii) 128 (iv) 1024
(iii) 11012 = 10 (v) 563 (vi) 2047
(iv) 1110 = 2 (vii) 17.75 (viii) 356.16
(v) 1110 = 16 (ix) 127.375 (x) 100.336
(vi) 2016 = 2 (xi) 61.0625 (xii) 49.0125
(vii) 2016 = 10 (xiii) 23.6125 (xiv) 36.625
(viii) 25910 = 2 (xv) 0.0525
(ix) 25910 = 16 3. Convert the following binary numbers to equivalent decimal numbers.
(x) 100000002 = 10 (i) 10110.101 (ii) 111001010.1011
(xi) 100010102 = 16 (iii) 110110.1101 (iv) 1011001.101
(xii) 102410 = 16 (v) 110101.001 (vi) 0.011011
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
Number Systems and Binary Arithmetic 41
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
4. Determine the equivalent octal numbers for the following decimal 11. Convert the following binary numbers to hexadecimal numbers.
numbers. (i) 101011
(i) 4 (ii) 25 (ii) 11001011
(iii) 261 (iv) 73 (iii) 11110110101
(v) 385 (vi) 621 (iv) 10111111001010
(vii) 10.25 (viii) 25.15 (v) 1101.01
(ix) 0.44 (x) 131.3 (vi) 1011110.1010
(xi) 0.046 (xii) 0.5 (vii) 10110.0011
5. Perform the following conversions from octal to decimal numbers. (viii) 1001011.01101001
(i) 11 (ii) 42 12. Perform the following conversions.
(iii) 507 (iv) 127 (i) 56710 = 16
7. Find the equivalent binary numbers for the following octal numbers. = 16
(i) 36 (ii) 14 = 8
(iii) 127 (iv) 251 13. Give 1’s complement representation of –710.
(v) 1723 (vi) 4.6 14. Give 2’s complement representation of a number whose 1’s
complement representation is 100112. What is the number in binary
(vii) 17.5 (viii) 64.05
representation?
(ix) 231.44 (x) 1025.625
15. Find the 1’s complement of
8. Convert the following decimal numbers to equivalent hexadecimal
(i) 1110011002 (ii) 110101112
numbers.
(iii) 100111112 (iv) 100000002
(i) 4181 (ii) 130
(v) –10102 (vi) –11012
(iii) 171 (iv) 4095
16. Find the 2’s complement of
(v) 30.10 (vi) 64.5
(i) 101102 (ii) 11001112
(vii) 10.04 (viii) 15.64
(iii) 011012 (iv) 010002
9. Convert the following hexadecimal numbers to equivalent decimal
(v) –11102 (vi) –10012
numbers.
17. Add the following numbers
(i) 4C (ii) 512
(i) 10112 + 01012
(iii) 100 (iv) BA2
(ii) 11112 + 01012
(v) B.2 (vi) 5.5
(iii) 112 + 1112
(vii) 4A.25 (viii) F.2
(iv) 100111112 + 011010112
10. Convert the following hexadecimal numbers to binary numbers.
18. Using 2’s complement method, perform the following operations:
(i) A2; (ii) B35;
(i) 3110 – 1710 (ii) 5110 – 2710
(iii) 54E; (iv) DAE;
(iii) 1210 – 1910 (iv) 2510 – 4910
(v) FE; (vi) 4A.6;
(v) –1910 – 1210 (vi) –1010 – 810
(vii) 74.5; (viii) C7.9D;
(vii) –1310 + 1010 (viii) –2310 + 4510
(ix) EF.2C; (x) ABC.F
(ix) 10012 + 01002 (x) 10102 – 11012
h a n g e Vi h a n g e Vi
XC e XC e
F- w F- w
PD
PD
er
er
!
!
W
W
O
O
N
N
y
y
bu
bu
to
to
42 Computer Fundamentals and Programming in C
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o . c .d o .c
c u -tr ack c u -tr a c k
19. Perform the following operations. The most significant bit represents 22. Convert the following decimal numbers to BCD representation:
the sign bit and the negative numbers are in 2’s complement form. (i) 810 (ii) 2610
(i) 00011011 + 00001101 (iii) 3710 (iv) 14510
(ii) 00011111 – 11001111 23. What are the equivalent Excess-3 code representations for the
20. If 2’s complement of a number in four-bits is 10112, give its 2’s following numbers in 8421 code:
complement representation in eight-bits. (i) 0011 (ii) 0101
21. Suppose a computer uses six-bits for base 2 unsigned integer and for (iii) 1001 (iv) 1000
2’s complement signed integers. 24. Find the decimal numbers represented by the given numbers in gray
(i) What range of values could be represented as an unsigned code:
integer? (i) 0011 (ii) 1011
(ii) What range of values could be represented as a signed integer? (iii) 0111 (iv) 1111