Sunteți pe pagina 1din 25

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
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

multiple numbers of sticks: | | | still meant three sticks, but


2.1  Introduction to Number Systems
a V meant five sticks, and a X was used to represent ten of
A number system defines a set of values used to represent them. Using sticks to count was a great idea at that time.
quantity. For example, the number of mobile phones kept in And using symbols instead of real sticks was much better.
a shop, the number of persons standing in a queue, and the One of the best ways to represent a number today is by using
number of students attending a class. the modern decimal system. Why? Because it includes the
There are many ways to represent the same numeric value. major breakthrough of using a symbol to represent the idea
Long ago, humans used sticks to count; they then learned of counting nothing. About 1500 years ago, in India, zero (0)
how to draw pictures of sticks on the ground and eventually was first used as a number. It was later used in the Middle
on paper. So, the number 5 was first represented as: | | | | | (for East as the Arabic, sifr. It was finally introduced in the West
five sticks). as the Latin, zephiro. Soon it was seen how valuable the
Later on, the Romans began using different symbols for concept of zero was for all modern number 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
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

(b) Polynomial form:


Important note  Any number raised to the power of zero is
N = d n − 1 × r n − 1 + d n − 2 × r n − 2 ... d 0 r 0 1, even zero raised to the power of zero is 1, for example,

+ d −1r −1 + d −2 r −2 ... d − m r − m 100 = 1, 00 = 1, x0 = 1
(c) Compact form:
2.4 Types of Number Systems
n -1
N = Â di r i There are several types number systems. Table 2.1 shows a
where i = -m list of number systems with their base and sets of valid digits.
d = value of the digit symbol, 2.4.1  Decimal Number System [Base-10]
r = base or radix,
n = the number of integral digits to the left of the decimal Most people today use decimal representation to count. This
point, and number system uses TEN different symbols to represent
m = the number of fractional digits or digits to the right of values. In the decimal system there are 10 digit symbols
the decimal point. 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9
with 0 having the least value and 9 having the greatest value.
For a number represented in decimal system, the digit on the
2.3  Weighting Factor extreme left has the greatest value, whereas the digit on the
The numerical value of a number is the sum of the products extreme right has the least value.
obtained by multiplying each digit by the weight of its ∑ Each position to the left increases by a weight of 10.
respective position. Decimal numbers are represented by
arranging the symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. These are Example
known as decimal digits, in various sequences. The position (i) 9 + 1 = 10 (nine plus one equals zero, carry one or 10)
of each digit in a sequence has a certain numerical weight, (ii)
3 2 1 0 Digit position
and each digit is a multiplier of the weight of its position. The
1 2 7 5 Decimal number
decimal number system is hence an example of a weighted,
5 ¥ 10 0 = 5
positional number system. The weight of each position is a 7 ¥ 10 1 = 70
power of the base number 10. 2 ¥ 10 2 = 200
Therefore, the weighting factor is the numerical value of 1 ¥ 10 3 = 1000
the multiplier for each column (digit) position of the number. 127510
For instance, the decimal number system has a weighting Multiplier (in decimal)
Weight (in decimal)

Table 2.1  Number systems, bases, and symbols


Number system Base Digital symbols
Binary 2 0, 1
Ternary 3 0, 1, 2
Quaternary 4 0, 1, 2, 3
Quinary 5 0, 1, 2, 3, 4
Octal 8 0, 1, 2, 3, 4, 5, 6, 7
Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Duodecimal 12 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B
Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Vigesimal 20 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J
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
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

0 ¥ 22 = 0 The hexadecimal system is often used to represent values


1¥2 =3
8 (data and memory addresses) in computer systems. Table 2.2
1110 shows the representation of decimal numbers ranging from 0
Multiplier Weight
to 15 in binary, octal, and hexadecimal number systems.
(in binary) (in binary)
Table 2.2  Number systems equivalency table
In a computer, a binary digit representing a binary value (0 or 1) is
Decimal Binary Octal (Base-8) Hexadecimal
called a BIT. That is, each digit in a binary number is called a bit, 4 bits form
(Base-10) (Base-2) (Base-16)
a NIBBLE, 8 bits form a BYTE, two bytes form a WORD and two words 0 0000 0 0
form a DOUBLE WORD (rarely used). 1 0001 1 1
An n-bit number can represent 2n different number values, for example, 2 0010 2 2
for an 8-bit number, 28 = 256 different values may be represented. 3 0011 3 3
4 0100 4 4
2.4.3  Octal Number System [Base-8] 5 0101 5 5
6 0110 6 6
The octal number system uses EIGHT digit symbols to
7 0111 7 7
represent numbers. The symbols are
8 1000 10 8
0, 1, 2, 3, 4, 5, 6, and 7
9 1001 11 9
with 0 having the least value and 7 having the greatest value. 10 1010 12 A
The number representation in the octal system is done in the 11 1011 13 B
same way as in the decimal system, in which the digit on the 12 1100 14 C
extreme left represents the most significant digit. 13 1101 15 D
∑ Each position to the left increases by a weight of 8. Thus, 14 1110 16 E
(i) 7 + 1 = 10 (seven plus one equals zero, carry one or 10) 15 1111 17 F
Digit position (in decimal)
(ii) 3 2 1 0
1 2 6 58 Octal number 2.4.5  Common Rules of Number Systems
5 ¥ 80 = 5 All number systems follow the following set of rules:
6 ¥ 81 = 48 Rule 1 The number of digit symbols available in a
2¥8 = 2
128
number system is equal to the base.
Examples:
1¥8 = 3
512
For the decimal system having base 10, there are 10
69310
digit symbols 0 through 9.
Multiplier Weight For the binary system having base 2, there are 2 digit
(in octal) (in octal)
symbols 0 and 1.
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 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

To avoid confusion, often a subscript is used with a number 2 127 0 LSB


to indicate the number system base. For example, 2 63 1
162h ‘h’ means hexadecimal 2 31 1
16216 16 means base-16 2 15 1 111111102
162d ‘d’ means decimal 2 7 1
16210 10 means base-10 2 3 1
162o ‘o’ means octal 2 1 1
1628 8 means base-8 0 1 MSB
101b ‘b’ means binary
Thus, the binary equivalent is 11111110.
1012 2 means base-2
Method 2  Power-of-2-subtraction method
note 1. Let D be the number that has to be converted from
∑ In all number system representations, the digit on the decimal to binary.
extreme left represents the greatest value and is called
2. (a) Find the largest power of two that is less than or
the most significant digit (MSD), whereas the digit on
the extreme right is known as the least significant equal to D. Let this equal P.
digit (LSD). (b) If |D| ≥ P, subtract P from D, obtain a result which is
∑ The value of the largest digit symbol is one less than a decimal number. Put 1 in the digit position where
the base. the weighting factor is P.
∑ A carry from one position to the next increases its (c) Otherwise, if |D| < |P|, put 0 in the corresponding
weight base times.
weighting factor column.
3. Repeat step 2 with D = remainder decimal number until
2.5  Number System Conversions D = 0, or |D| < |P|.

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

Weighting factor 128 64 32 16 8 4 2 1 Conversion of a decimal number to its octal


Binary mumber 1 equivalent
To convert from decimal whole numbers to octal, the
This leaves a remainder (247 – 128) = 119. For 119, for which the
systematic approach called the repeated-division-by-8
highest power of 2 is 64, 1 is put in digit position with the weighting factor
method is used. This method is explained by the following
64.
example.
128 64 32 16 8 4 2 1
1 1 Example
 Converting (359)10 to octal.
This leaves a remainder (119 – 64) = 55. Weight 32 fits; therefore, 1 is
put in the corresponding digit position as follows: (a) Divide the decimal number by eight and obtain a quotient and a
remainder.
128 64 32 16 8 4 2 1
(b) Divide the quotient by eight and obtain a new quotient and a
1 1 1
remainder.
This leaves a remainder (55 – 32) = 23. Weight 16 fits; thus 1 is put in (c) Repeat step (b) until the quotient is equal to zero (0).
the digit position with weight 16. (d) The first remainder produced is the LSB in the octal number and
128 64 32 16 8 4 2 1 the last remainder (R) is the MSB. Accordingly, the octal number
is then written (from left to right) with the MSB occurring first.
1 1 1 1
Decimal Quotient Remainder
This leaves (23 – 16) = 7 as remainder. This is smaller than the next Divisor number (R)
digit position weight value 8. So 0 is put under 8. Next, find the weight that
fits; thus, 1 is placed in the digit position with weight 4. Hence, (7 – 4) = 3 8 359
is left. 8 44 7 (LSB)
128 64 32 16 8 4 2 1 8 5 4 5478
1 1 1 1 0 1 0 5 (MSB)
Weight 2 fits; thus a 1 is put under the digit position with weight 2.
Therefore, (3 – 2) = 1 is left, which is put in digit position with weight 1, that Therefore, (359)10 = (547)8
is, 20.
Conversion of an octal number to its decimal
128 64 32 16 8 4 2 1 equivalent
1 1 1 1
To express the value of a given octal number as its decimal
Hence, 247 in base 10 is the same as 11110111 in base 2. equivalent, add the octal digits after each digit has been
multiplied by its associated weight.
Conversion from binary to decimal
To express the value of a given binary number as its decimal Example
equivalent, sum the binary digits after each digit has been Converting (237)8 to decimal form.
multiplied by its associated weight. 2 1 0 Digit position
2 3 7 Octal number
Example
7 ¥ 80 = 7
 Converting (110101)2 to its decimal equivalent.
3¥8 =1
24
5 4 3 2 1 0 Digit position
2¥8 =2
128
1 1 0 1 0 1 Binary number
159 Decimal number
1 ¥ 20 = 1
Multiplier Weight
0 ¥ 21 = 0
1 ¥ 22 = 4
Conversion of an octal number to its binary
0¥2 = 3
0 equivalent
1 ¥ 24 = 16
Since each octal digit can be represented by a three-bit
1¥2 = 5
32 binary number (see Table 2.3), it is very easy to convert
5310 Decimal from octal to binary. Simply replace each octal digit with
value
the appropriate three-bit binary number as indicated in the
Multiplier Weight
following example.
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 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

0 000 Converting the hexadecimal number A4D31 to its equivalent decimal


number.
3 011
The decimal value of each digit in relation to its positional weight value
2 010 is evaluated first:
1 001 4 3 2 1 0 Digit position

Hexadecimal number
Conversion of a binary number to its equivalent
A 4 D 3 116

octal number 1 ¥ 160 = 1¥1 = 1


Converting a binary number to an octal number is a simple 3 ¥ 16 =1
3 ¥ 16 = 48
process. Break the binary digits into groups of three
D ¥ 16 =2
13 ¥ 256 = 3328
starting from the binary point and convert each group into
4 ¥ 16 =3
4 ¥ 4096
its appropriate octal digit. For whole numbers, it may be = 16384

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

Binary number 010 111

Equivalent octal number 2 7 Conversion of a hexadecimal number to its binary


equivalent
Conversion of a decimal number to its hexadecimal As each hexadecimal digit can be represented by a four-bit
equivalent binary number (see Table 2.4), it is very easy to convert from
The decimal number to be converted is divided by 16 until hexadecimal to binary. Simply replace each hexadecimal
the quotient is 0. The hexadecimal number is formed from digit with the appropriate four-bit binary number as indicated
the remainders. 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
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

5 0101 5 Conversion from hexadecimal to octal, and octal


6 0110 6 to hexadecimal
7 0111 7 To convert from hexadecimal to octal, each digit of the
8 1000 8 hexadecimal number is written as its equivalent four-bit
binary number. The resulting binary number is divided into
9 1001 9
groups of three binary digits. Then corresponding octal
10 1010 A numbers for each of these groups are written.
11 1011 B
Example
12 1100 C
Converting the hexadecimal number AF35D02 to its equivalent octal
13 1101 D
number.
14 1110 E The given number is rewritten by replacing the hexadecimal digits by
15 1111 F their equivalent four-bit binary numbers.
In groups of three bits
Example A 1010
Converting 123416 to a binary number. F 1111
Hexadecimal number 1 2 3 4 3 0011
5 0101
Equivalent binary number 0001 0010 0011 0100
d 1101
0 0000
Example 2 0010
Converting 37B16 to a binary number.
The binary number is regrouped as three-bit binary numbers that are
Hexadecimal number 3 7 B
replaced with octal symbols.
Equivalent binary number 0011 0111 1011
In groups of three bits Octal number

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

(b) Converting 37.128 to equivalent binary number. 1 0001 1


Octal number 3 7 . 1 2 2 0010 2
Binary number 011 111 . 001 010 3 0011 3
4 0100 4
Conversion from binary fraction to octal
5 0101 5
Converting binary to octal is also a simple process. Arrange 6 0110 6
the binary number into groups of three bits starting from
7 0111 7
the binary point and convert each of these groups into its
8 1000 8
appropriate octal digit symbol. For whole numbers, it may
9 1001 9
be necessary to add a zero with the MSD in order to form
a grouping of three bits. Note that this does not change the 10 1010 A
value of the binary number. Similarly, when representing 11 1011 B
fractions, it may be necessary to add a trailing zero in the
LSD in order to form a complete grouping of three bits. Conversion from hexadecimal fraction to binary
Because each hexadecimal digit can be represented by
Example a four-bit binary number, it is very easy to convert from
(a) Converting (010.111)2 to octal hexadecimal to binary. Simply replace each hexadecimal
digit with the appropriate four-bit binary number as indicated
Binary number 0 1 0 . 1 1 1 in the following example.

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

1. What is the binary equivalent of the decimal number +0 +1 +0 +1


368 0 1 1 10
(a) 101110000 (c) 110110000
These rules can be used to derive another important rule
(c) 111010000 (d) 111100000 for binary arithmetic. Consider what happens when three 1’s
Answer: (a) are added together in binary. Let the problem be split into two
2. The decimal equivalent of hex number 1A53 is addition problems; the answer is obtained by applying the
(a) 6793 (b) 6739 rule for binary addition.
(c) 6973 (d) 6379 1.  Apply Rule 4 to find the sum of the first two 1
Answer: (b) 1’s.
+1
3. (734)8 = ( ? )16
10
(a) C 1 D (b) D C 1
(c) 1 C D (d) 1 D C 2.  Next, take the previous result of 102 and add 10
the final 1 to it. Notice that Rule 2 (0 + 1 = 1)
Answer: (d) +1
is used to find the answer to the first column,
4. The hexadecimal number for (95.5)10 is and Rule 3 (1 + 0 = 1) is used to find the 11
(a) (5F.8)16 (b) (9A.B)16 answer to the second column.
(c) (2E.F)16 (d) (5A.4)16 3.  Hence another rule has been derived for 1
Answer: (a) binary arithmetic. The sum of three 1’s in
+1
5. Determine the binary number represented by 0.6875 binary is 112.
11
Answer: 0.10112
6. The octal equivalent of (247)10 is It is important to remember that in binary addition, two 1’s
always generate a carry to the next column. This happened in
(a) (252 )8 (b) ( 350 )8
the preceding example. Adding the first two 1’s gives a carry
(c) ( 367 )8 (d) ( 400 )8
to the next column and the remaining 1 becomes the value for
Answer: (c) the current column.

2.6 Binary Arithmetic Example


 Adding 11112(1510) and 01102 (610).
In computers, numbers are represented in binary form. The
Solution:  The binary numbers 11112 and 01102 can be added in the same
arithmetic operations performed by a computer therefore
way the decimal numbers 1510 and 610 are added.
involves binary numbers. The next few sections describe how
binary arithmetic operations like binary addition, subtraction, 1. The numbers in the rightmost column are added. 1
multiplication, and division are performed. In this context, plus 0 adds up to 1.
it may be mentioned that such arithmetic operations are 0 Carry
primarily performed by the ALU within the computer 0 1 1 1 1
system. + 0 0 1 1 0

2.6.1  Addition 1 Result

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

2.  In order to subtract the second column, a 1¸


Table 2.12  Rules for binary subtraction
1 has to be borrowed. So, cross out the ˝ Borrow
Rule 1 Rule 2 Rule 3 Rule 4
01 ˛
1 in the third column, and represent it as
0 1 1 0 two 1’s in the second column. 10 101Minuend
–0 –1 –0 –1 - 01110 Subtrahend
0 0 1 1 1 Result
3.  1 can now be subtracted from the group 1¸
The first three rules are similar to the decimal system rules.
of two borrowed 1’s. This leaves a 1, so it ˝ Borrow
The fourth rule, however, needs a little more explanation 01 ˛
is written below the second column.
since it defines how borrowing is done from another column. 10 101Minuend
Let us look at a simple example to see where this rule comes - 01110 Subtrahend
from. Consider the problem of subtracting 12 from 102. 11 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
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

101001 010110 2. Convert 00012 to its sign bit 1’s complement


negative equivalent in 1’s
complement. To do this, 0001 Subtrahend in
note change 1’s complement
1110 1’s complement
from
∑ –0 and +0 are represented differently even though they all 1’s to 0’s and 0’s to 1’s
are the same algebraically. in 00012 form. Notice that
∑ This causes problems when carrying out tests on the most significant digit is
arithmetic results. now 1 since the number is
∑ Hence, 1’s complement is an unpopular choice for integer negative.
representation.
3.  Add the negative value 0101
∑ Most computers now use a variation of 1’s complement
11102 to 01112. This gives +1
(called 2’s complement) that eliminates the problem. 0110 (6) Sum
the sum 101012. Overflow bit

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

Subtraction using signed 1’s complement Example


representation
 Subtracting 10012(910) from 11012(1310) using 1’s complement.
In this type of representation, subtraction is carried out by Solution:
addition of 1’s complement of the negative number. The sign The subtraction between binary numbers 11012(1310) and 10012(910)
bit is treated as a number bit in the subtraction method. For can be carried out by converting 10012 to its negative equivalent in 1’s
the sign bit being 0, i.e., positive, the magnitude part of the complement and adding this value to 11012.
result is the true value. For the sign bit being 1, i.e., negative,
1.  The problem is stated in binary sign bit
the magnitude part of the result is in 1’s complement form.
numbers.
For subtracting a smaller number from a larger number, the 01101 (13)
1’s complement method is implemented as follows. – 01001 – (9)
1. Determine the 1’s complement of the smaller number.
2. Add the 1’s complement to the larger number.
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
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

2.  Convert 010012 to its negative 01101 10110 Example


equivalent in 1’s complement. Subtracting 11012(1310) from 10012(910) using 1’s complement.
To do this, change all the 1’s Solution:
to 0’s and 0’s to 1’s. Notice that 1001 – 1101
the most significant digit is now Result from Step 1 0010
1 since the number is negative. Result from Step 2 1011
3.  Add the negative value 101102 01101 (13) Result from Step 3 –0100
to 011012. This gives the sum + 10110 + (–1)
True To verify, note that 9 –13 = –4
110001 (?) magnitude
1000112. 1.  The problem is stated. 01001 (9)
– 01101 – (13)
4.  Note that the addition caused 00011
an overflow bit. Whenever an +1 True 2. Convert 011012 to its 01001 (9)
00100 (4) magnitude
overflow bit occurs in such negative equivalent in 1’s + 10010 (–13)
a method, add this bit to the 11011
complement and add to Magnitude in 1’s
sum to get the correct answer. sign bit 010012. complement
Hence, the result is 001002 (or sign bit
410).
3.  The sign bit of the sum sign bit
For subtracting a larger number from a smaller number,
being 1, the resulting
the 1’s complement method is as follows: 11011 (–4)
number is negative and the Result in signed
1. Determine the 1’s complement of the larger number. value is in 1’s complement 1’s complement
2. Add the 1’s complement to the smaller number. form.
3. There is no carry (overflow). The result has the proper
sign bit but the answer is in 1’s complement of the true Subtraction using signed 2’s complement
magnitude. representation
4. Take the 1’s complement of the result to get the final Subtraction for this representation is done by addition of
result. The sign of the result is obtained from the sign bit
the 2’s complement of the negative number. The sign bit is
of the result.
treated as a number bit during subtraction. Thus, the result
is obtained with the sign bit. When the sign bit is 0, i.e.,
Example
positive, the magnitude part of the result is the true value.
 Subtracting 710 from 110 using 1’s complement. But when the sign bit is 1, i.e., negative, the magnitude part
Solution: of the result is in 2’s complement form. Therefore, the 2’s
1.  State the problem with 0001 (1) Minuend complement of the magnitude part of the result gives the true
the numbers in binary. – 0111 – (7) Subtrahend value. The carry bit that evolves with the sum is ignored in
the 2’s complement method.
2.  Convert negative 01112 sign bit For subtracting a smaller number from a larger number, the
to 1’s complement and
2’s complement method is implemented as follows.
add this to 00012. 0001 (1) Minuend
+ 1000 + (–7) Subtrahend in 1. Determine the 2’s complement of the smaller number.
1’s complement
1001 (?)
from 2. Add the 2’s complement to the larger number.
sign bit 3. Discard the final carry (there is always one in this
case).
3.  The result does not cause sign bit
an overflow, so the sum Example
need not be adjusted. 0001 (1)
Note that the final result + 1000 + (–7)  Subtracting 110 from 710 using 2’s complement.
Result in signed
is a negative number
1001 (–6)
1’s complement Solution:
from
since the sign bit is 1. Now, 110 = 00012 and 710 = 01112.
sign bit Magnitude in 1’s
Therefore, the result is in complement
1’s complement notation; sign bit
the correct decimal
value for the result is –610
1.  The problem is stated with 0111 (7)
and not 910. This is
numbers in binary. + 0001 + (–1)
obtained by taking the 1’s
complement of the 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 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

2.7  Binary Codes 2.7.1 Numeric Codes


Numeric codes represent numeric data with a series of 0’s
For practical reasons, it is very convenient to use the binary
and 1’s. Decimal numbers 0 to 9 can be represented by four
number system in digital systems or computers. Data is
binary digits. Of the 16 possible combinations of the four
represented by symbols in the form of decimal numbers,
binary digits, only 10 combinations are used to represent the
alphabets, and special characters. To facilitate extensive
decimal numbers 0 to 9. Each of these bit combinations that
communication between humans and digital machines, binary
represent a specific decimal digit is called a code word.
digits 1 and 0 are arranged according to certain defined rules
The numeric codes devised to represent decimal digits are
and designated to represent symbols. The method of forming
known as binary coded decimal (BCD) codes. There are
the binary representation is known as encoding and the
several BCD codes. These are of two kinds: weighted and
complete group of binary representations corresponding to
non-weighted.
the symbols is known as binary code.
Binary codes may be broadly classified into four categories. Weighted codes
(a) Numeric codes Weighted codes obey the position weighting principle, where
(b) Alphanumeric codes each bit position is assigned a decimal weight. For such a
(c) Error-detecting codes code, the sum of the decimal weights of those bits whose
value is ‘1’ is equal to the decimal digit it represents. For
(d) Error-correcting codes
example, in a four-bit weighted code, if w1, w2, w3, and w4 are
Numeric codes are further classified as weighted, non-
the decimal weights of the binary digits and b1, b2, b3, and b4
weighted, self-complementing, sequential, and cyclic codes
are the corresponding bit values, then the decimal digit ‘N’
as depicted in Fig. 2.1.
is given by
N = w4.b4 + w3.b3 + w2.b2 + w1.b1
Binary codes
whose BCD code representation is b4b3b2b1.
This binary sequence code is the code word for the decimal
Numeric Alphanumeric Error- Error- number N.
codes codes detecting correcting
codes codes
Weighted codes are of two types:
(a) Positively weighted codes
Weighted Non-weighted (b) Negatively weighted codes
codes codes
Positively weighted codes  are BCD codes in which all
Negatively Positively the weights assigned to the bits are positive. There are 17
weighted weighted positively weighted code in a four-bit BCD code. It should be
codes codes
noted that in every positively weighted code, the first weight
should be 1, the second weight should either be 1 or 2, and
Self- Sequential Cyclic the sum of all the weights should be greater than or equal to
complementing codes codes
codes or
the decimal number 9.
reflective
Negatively weighted codes  are BCD codes in which some
of the weights assigned to the bits are negative. Table 2.13
Fig. 2.1  Code classification
depicts some of the weighted codes.

Table 2.13  Some weighted binary coded decimals


Decimal digits Positive weights (w4, w3, w2, w1) Negative weights (w3, w2, w1)
8421 5421 5211 2421 8 4 –2 –1 6 4 –2 –3
0 0000 0000 0000 0000 0000 0000
1 0001 0001 0001 0001 0111 0101
2 0010 0010 0011 0010 0110 0010
3 0011 0011 0101 0011 0101 1001
4 0100 0100 0111 0100 0100 0100
5 0101 1000 1000 1011 1011 1011
6 0110 1001 1001 1100 1010 0110
7 0111 1010 1011 1101 1001 1101
8 1000 1011 1101 1110 1000 1010
9 1001 1100 1111 1111 1111 1111
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 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.

Frequently asked questions


1.  What is a binary number? Herein, it may be noted that as the number value increases the
Answer: digit positions on the left-hand side of the binary equivalent number
A binary number is made of 0s and 1s. In the binary number system increases. Each increase of the digit position to the left signifies an
only two symbols, 0 and 1, are used to represent numeric values. The increase by 2 in the value of the number represented in the binary
symbol “0“ represents the value “zero” while the symbol “1” represents number system. Since the number of symbols in the binary number
the value “one”. Since there are only two symbols in the binary number system is two, the radix of this number system expressed in decimal
system, the value “two” is represented by placing the symbol “1” on is 2.
the left–hand side of the symbol “0” resulting in the binary equivalent
“10”. Next, the value “three” is represented by “11” in the binary number 2.  What is meant by ‘bit’?
systemby replacing the “ 0 ” in “10” by the next higher value symbol “1”. Answer:
A sample table depicting the binary equivalent representation for different The abbreviated form of “ bi-nary dig-it ” is known as bit. When a “bit” is
decimal numbers upto nine is shown below. mentioned, it means a single binary digit, which may either be a “0” or
Decimal number Binary equivalent “1”, is referred to.
(Number value) representation 3.  Why do digital computers use binary numbers for their
0 0 operations?
1 1 Answer:
2 10 A survey of the history of development of computers would reveal that the
3 11 primary objective of computer designers as to construct a computer that
4 100 would carry out all types of arithmetical calculations. This was achieved
5 101 by initially employing mechanical devices and then improving it with
6 110 the addition of electrical devices. But these computing machines were
7 111 calculators with no programmable facilities. The need for programmability
8 1000 was also met using the mechanical and electrical devices. Meanwhile
9 1001 analog computers were in use for solving not only arithmetical problems but
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
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

(v) 100 (vi) 63.4 = 8

(vii) 5.6 (viii) 0.1 (ii) A6C216 = 8

(ix) 13.5 (x) 36.05 = 2

6. Convert the following binary numbers to octal numbers. (iii) B.2C16 = 8

(i) 1101 (ii) 101101 = 10

(iii) 1101111 (iv) 111111 (iv) 1011110011111.0112


(v) 10100 (vi) 0.11 = 16

(vii) 0.101 (viii) 1001.01101 = 8

(ix) 11.110011 (x) 1100.1101 (v) 1010110000112

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

S-ar putea să vă placă și