1.2 Binary Numbers in Computer by KShare

1.1 Digital Systems
1.2 Binary Numbers
1.3 Number‐Base Conversions
1.5 Complements of Numbers
1.6 Signed Binary Numbers
1.7 Binary Codes
1.8 Binary Storage and Registers
1.9 Binary Logic

1.2  B I N A R Y  N U M B E R S

A decimal number such as 7,392 represents a quantity equal to 7 thousands, plus 3 hun-
dreds, plus 9 tens, plus 2 units. The thousands, hundreds, etc., are powers of 10 implied
by the position of the coefficients (symbols) in the number. To be more exact, 7,392 is a
shorthand notation for what should be written as
7 * 103 + 3 * 102 + 9 * 101 + 2 * 100

However, the convention is to write only the numeric coefficients and, from their posi-
tion, deduce the necessary powers of 10 with powers increasing from right to left. In
general, a number with a decimal point is represented by a series of coefficients:
a5a4a3a2a1a0. a-1a-2a-3
The coefficients aj are any of the 10 digits (0, 1, 2, c, 9), and the subscript value j gives
the place value and, hence, the power of 10 by which the coefficient must be multiplied.
Thus, the preceding decimal number can be expressed as
105
a5 + 104
a4 + 103
a3 + 102
a2 + 101
a1 + 100
a0 + 10-1
a-1 + 10-2
a-2 + 10-3
a-3
with a3 = 7, a2 = 3, a1 = 9, and a0 = 2.
The decimal number system is said to be of base, or radix, 10 because it uses 10 digits
and the coefficients are multiplied by powers of 10. The binary system is a different
number system. The coefficients of the binary number system have only two possible
values: 0 and 1. Each coefficient aj is multiplied by a power of the radix, e.g., 2j
, and
the results are added to obtain the decimal equivalent of the number. The radix
point (e.g., the decimal point when 10 is the radix) distinguishes positive powers of
10 from negative powers of 10. For example, the decimal equivalent of the binary
number 11010.11 is 26.75, as shown from the multiplication of the coefficients by
powers of 2:
1 * 24 + 1 * 23 + 0 * 22 + 1 * 21 + 0 * 20 + 1 * 2-1 + 1 * 2-2 = 26.75
There are many different number systems. In general, a number expressed in a base‐r
system has coefficients multiplied by powers of r:
an # r n + an-1 # r n-1 + g + a2 # r 2 + a1 # r + a0 + a-1 # r-1+ a-2 # r-2 + g + a-m # r-m
The coefficients aj range in value from 0 to r - 1. To distinguish between numbers of
different bases, we enclose the coefficients in parentheses and write a subscript equal to
the base used (except sometimes for decimal numbers, where the content makes it obvi-
ous that the base is decimal). An example of a base‐5 number is
(4021.2)5 = 4 * 53 + 0 * 52 + 2 * 51 + 1 * 50 + 2 * 5-1 = (511.4)10
The coefficient values for base 5 can be only 0, 1, 2, 3, and 4. The octal number system
is a base‐8 system that has eight digits: 0, 1, 2, 3, 4, 5, 6, 7. An example of an octal number
is 127.4. To determine its equivalent decimal value, we expand the number in a power
series with a base of 8:
(127.4)8 = 1 * 82 + 2 * 81 + 7 * 80 + 4 * 8-1 = (87.5)10
Note that the digits 8 and 9 cannot appear in an octal number.
It is customary to borrow the needed r digits for the coefficients from the decimal
system when the base of the number is less than 10. The letters of the alphabet are used
to supplement the 10 decimal digits when the base of the number is greater than 10. For
example, in the hexadecimal (base‐16) number system, the first 10 digits are borrowed from the decimal system. The letters A, B, C, D, E, and F are used for the digits 10, 11,
12, 13, 14, and 15, respectively. An example of a hexadecimal number is
(B65F)16 = 11 * 163 + 6 * 162 + 5 * 161 + 15 * 160 = (46,687)10
The hexadecimal system is used commonly by designers to represent long strings of bits
in the addresses, instructions, and data in digital systems. For example, B65F is used to
represent 1011011001010000.
As noted before, the digits in a binary number are called bits. When a bit is equal to
0, it does not contribute to the sum during the conversion. Therefore, the conversion
from binary to decimal can be obtained by adding only the numbers with powers of two
corresponding to the bits that are equal to 1. For example,
(110101)2 = 32 + 16 + 4 + 1 = (53)10
There are four 1’s in the binary number. The corresponding decimal number is the sum
of the four powers of two. Zero and the first 24 numbers obtained from 2 to the power of
n are listed in Table 1.1 . In computer work, 210 is referred to as K (kilo), 220 as M (mega),
230 as G (giga), and 240 as T (tera). Thus, 4K = 212 = 4,096 and 16M = 224 = 16,777,216.
Computer capacity is usually given in bytes. A byte is equal to eight bits and can accom-
modate (i.e., represent the code of) one keyboard character. A computer hard disk with
four gigabytes of storage has a capacity of 4G = 232 bytes (approximately 4 billion bytes).
A terabyte is 1024 gigabytes, approximately 1 trillion bytes.
Arithmetic operations with numbers in base r follow the same rules as for decimal
numbers. When a base other than the familiar base 10 is used, one must be careful to
use only the r‐allowable digits. Examples of addition, subtraction, and multiplication of
two binary numbers are as follows:
augend: 101101 minuend:    101101 multiplicand: 1011
addend: +100111 subtrahend: -100111 multiplier:    * 101
sum:     1010100 difference:   000110 1011
0000
1011
product:    110111
Table 1.1
Powers of Two
n 2n n 2n n 2n
0 1 8 256 16 65,536
1 2 9 512 17 131,072
2 4 10 1,024 (1K) 18 262,144
3 8 11 2,048 19 524,288
4 16 12 4,096 (4K) 20 1,048,576 (1M)
5 32 13 8,192 21 2,097,152
6 64 14 16,384 22 4,194,304
7 128 15 32,768 23 8,388,608

The sum of two binary numbers is calculated by the same rules as in decimal, except
that the digits of the sum in any significant position can be only 0 or 1. Any carry
obtained in a given significant position is used by the pair of digits one significant posi-
tion higher. Subtraction is slightly more complicated. The rules are still the same as in
decimal, except that the borrow in a given significant position adds 2 to a minuend digit.
(A borrow in the decimal system adds 10 to a minuend digit.) Multiplication is simple:
The multiplier digits are always 1 or 0; therefore, the partial products are equal either
to a shifted (left) copy of the multiplicand or to 0.