Unit I Binary numbers and Arithmetic
Unit I Binary numbers and Arithmetic
1.0 OBJECTIVES
At the end of this unit, the student will be able to:
• Explain the number system and its usage in computer systems
6
Computer Organization and Architecture
ideal system to use in a digital computer. But human being is
comfortable doing computations in the decimal number system.
i.e., 3 hundred, plus 2 tens, plus 2 units, plus 1 tenths. This way one
can calculate the quantity represented by any decimal number.
Binary (Base 2) Number System
(101001)2 = (41)10
7
Computer Organization and Architecture
2 28 0
2 14 0
2 7 1
2 3 1
2810 = (11100)2
Binary Addition
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
0 0 0 0
0 1 0 1
1 0 1 0
1 1 0 0
0 0 0
0 1 0
1 0 0
1 1 1
When all the inputs are 1, result is 1 and result is always 0, whenever
at least one input is 0.
9
Rules for binary division:
0 0 Not defined
0 1 0
1 0 Not defined
1 1 1
The result is always not defined, whenever the divisor is 0. Octal (base
8) and Hexadecimal (base 16) Number System Digits of the octal
number system are 0, 1, 2, 3, 4, 5, 6, and 7.
Digits of Hexadecimal number system are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, and F, alsocalled as hex digits. Both follow positional
notation.
Examples:
(136.6)8 = 1 x 82 + 3 x 81 + 6 x 80 + 6x 8-1
= 1 x 64 + 3 x 8 + 6 x 1 + 6/8 = (94.75)10
10
Computer Organization and Architecture
Convert 261(base 10) to hexadecimal (base 16):
quotient remainder
261 5
16
16 16 0
261D = 105H
1. 999-52= 947.
2. 167+947=1114
11
One’s Complement of a Signed Binary Number
The one‘s complement of ―1‖ is ―0‖ and vice versa. For example,
just by complementing each bit of 101101012, we get its one‘s
complement 010010102.
Step 1: Convert the two decimal numbers into binary. Make sure that
each number has the samenumber of bits by adding leading zeros to
produce an 8-bit number (byte). Therefore:
01100011+ 11101000
Overflow → 1 01001011
12
Computer Organization and Architecture
overflow can be ignored or passed to next circuit if system works
with 8 bits.
01001011
+1
010011002
13
Consider the subtraction of two 8-bit numbers 99 and 23 using
two‘s complement.
Step 1: Convert the two decimal numbers into binary. Make sure that
each number has the samenumber of bits by adding leading zeros to
produce an 8-bit number (byte). Therefore:
(01100011)2
+ (11101001) 2 = (101001100) 2
The 9th overflow bit is disregarded, so the result is: (01001100)2 or (64
+ 8 + 4) = 7610.
(r - l)’s Complement
(r’s) Complement
15
nonzero least significant digit from 10, and then subtracting all
higher significant digits from 9. The 10‘s complement of 4680 is
5320 and is obtained by leaving the first zero unchanged, subtracting
8 from 10, and subtracting the other two digits from 9. Similarly, the
2‘s complementcan be formed by leaving all least significant 0‘s and
the first 1 unchanged, and then replacing l‘s by 0‘s and 0‘s by l‘s in
all other higher, significant bits. The 2‘s complement of 10010 is
01110 and is obtained by leaving the first 0 and the first 1
unchanged, and then replacing l‘s by 0‘s and 0‘s by l‘s in the other
three most significant bits.
Weighted codes
Suppose W1, W2, W3 and W4 are the weights of binary digits and
Xl, X2, X3 and X4 are the corresponding digit values then decimal
digit, N = W1 Xl + W2 X2 + W3 X3 + W4 X4 is represented by
binary sequence X4 X3 X2 X1.
16
Computer Organization and Architecture
Suppose W1, W2, W3 and W4 are the weights of binary digits and
Xl, X2, X3 and X4 are the corresponding digit values then decimal
digit, N = W1 Xl + W2 X2 + W3 X3 + W4 X4 is represented by
binary sequence X4 X3 X2 X1.
Non-weighted codes:
Reflective codes
Sequential codes:
Codes which help in error detection and correction of data are called
error detecting and correcting codes.
Gray Code
17
Computer Organization and Architecture
The Figure 1.1 lists the Gray code equivalents of the decimal number
0 – 15.
They are also called as the minimum change code as the successive
coded characters never differ in more than one-bit. Due to this
feature, the maximum error that can creep into a system is much less
than the worst -case error encountered in case of straight binary
encoding.
Let us consider a few examples. The four-bit Gray code for decimal
number 39 is 00101101.
Excess-3 code
The Excess-3 code is formed by adding ‗3‘ to each digit and then
replacing each digit by its four-bit binary equivalent.
The key feature of the Excess-3 code is .that it is self-
complementing. In other words, the l‘s complement of an Excess-3
number is the Excess-3 code for the 9‘s complement of the
corresponding decimal number. For example, the Excess-3 code for
decimal 6 is (0110+0011)=1001. The l‘s complement of 1001 is
0110, which is the Excess-3 code for decimal
Digit BCD
0 0000
1 0001
2 0010
3 0011
4 0100
20
Computer Organization and Architecture
5 0101
6 0110
7 0111
8 1000
9 1001
Zones
1111 Unsigned
1100 Positive
1101 Negative
ASCII characters most often are stored one per byte, though it is a
7-bit code. Most computers manipulate an 8-bit quantity as a single
unit called a byte. Therefore, ASCII characters most often are stored
one per byte. The extra bit is sometimes used for other purposes,
depending on the application. For example, some printers recognize
8-bit ASCII characters with the most significant bit set to 0.
Additional 128 8-bit characters with the most significant bit set to 1
are used for other symbols, such as the Greek alphabet or italic type
font. When used in data communication, the eighth bit may be
employed to indicate the parity of the binary-coded character. It
is possible to convert decimal digits in ASCII to BCD by removing
the three high-order bits, 011.
..........................................................................................................
..........................................................................................................
..........................................................................................................
..........................................................................................................
22
Computer Organization and Architecture
3 What is the rule of number system?
..........................................................................................................
..........................................................................................................
..........................................................................................................
..........................................................................................................
0+0=0
0+1=1
23
1+0=1
For example, let us add two binary numbers 10001001 and 10010101.
Binary Subtraction
0–0=0
1–0=1
1–1=0
Binary Multiplication
0×0=0
1×0=0
0×1=0
24
Computer Organization and Architecture
Following are the steps to multiply binary numbers 10001001 and
10010101
Binary Division
Binary division is comprised of multiplication and subtraction;
Consider following example, which explains the operation more
easily.
Fixed-point numbers
25
Figure 1.3 Truth table and schematic diagram for a binary half-adder
The truth table for the carry output is the logical AND of the two
inputs, while the sum output is the exclusive OR (XOR) of the
inputs. Half adder has the limitation of adding only two inputs. It
can be extended to binary Fulladder(FA) by adding a carry input .
Figure 1.4 shows the truth table and schematic diagram of Binary
full adder.
Figure 1.4 Truth table and schematic diagram for a binary full adder
Multiplication
26
Computer Organization and Architecture
The figure 1.5 shows 4-digit multiplicand and 4 digit multiplier
resulting in 4 partial products (either all 0s (if the corresponding yi
= 0) or the same as x (if yi = 1). This method adds the multiplicand
X to itself Y times, where Y denotes the multiplier.
Division
27
Figure 1.6 Division of an 8-bit number by a 4-bit number in dot
notationFloating point representation
Fraction Exponent
+0.987734 +03
The value of the exponent indicates that the actual position of the
decimal point is three positions to the right of the indicated decimal
point in the fraction.
Fraction Exponent
01011010 000100
m x 2e = +(.01011010)2 x 2+4
28
Computer Organization and Architecture
A floating-point number is said to be normalized if the most
significant digit of the mantissa is nonzero. For example, the 8-bit
binary number 00011100 is not normalized. when normalizedthe
number becomes 11100000. As the three shifts multiply the number
by 23 = 8, the exponent must be subtracted by 3. Normalized
numbers provide the maximum precision for the floating- point
number. A zero is represented in floating-point by all 0‘s in the
mantissa and exponent.
..........................................................................................................
..........................................................................................................
..........................................................................................................
..........................................................................................................
29
3. What are the 4 types of number system?
..........................................................................................................
..........................................................................................................
..........................................................................................................
......................................................................................................
Boolean Algebra
Boolean algebra is an algebra for objects that can take on only two
values, typically true(1) and false(0). Boolean algebra is ideal for
computer arithmetic as computers are built as collections of switches
that are either ―on‖ or ―off or low and high voltages.
Three common Boolean operators are AND, OR, and NOT. A truth
table shows the relationship, between the input values and the result
of a specific Boolean operator or function on the input variables. It
lists all possible combinations of inputs along with their output.
―not x.‖
30
Computer Organization and Architecture
31
Computer Organization and Architecture
0 x= 0
1+A+B+C=1
B
+
A
B
´
C
B
+
A
´
+
B
C
´
DeMorgan‘s law A´+B´+C´
Inverse law 1
True law
A
B
+
A
´
B
+
A
B
´
+
A
´
B
´
(
A
+
A
´
34
Computer Organization and Architecture
)
B
+
A
B
´
+
A
´
B
´
Distribution law 1B+AB´+A´B´Inverse law B+AB´+A´B´
True law B+(A+A´)B´
Distribution law B+1B´
Inverse law B+B´
True law 1
Logic Gates
35
Table 1.9 Truth tables showing all possible functions of two
binary variables
36
Computer Organization and Architecture
Gates
Gates are the basic building blocks for digital design. It is a small,
electronic device that computes various functions of two-valued
signals. A gate implements a simple Boolean function. To physically
implement each gate requires one to six or more transistors,
depending on the technology being used.
AND
The AND gate produces the AND logic function: that is, the output
is 1 if input A and input Bare both equal to 1; otherwise, the output
is 0. These conditions are also specified in the truth table for the
AND gate. In general, the output x is 1 only when all inputs are 1.
The algebraic operation symbol of the AND function is the same as
the multiplication symbol of ordinary arithmetic.
The OR gate produces the inclusive-OR function; that is, the output
is 1 if any or all inputs are 1; otherwise, the output is 0.
OR gates may have more than two inputs, and the output is 1 if any
input is 1.
38
Computer Organization and Architecture
The XOR (exclusive-OR) gate acts in the same way as the logical
"either/or." The output is "true"(1) if either, but not both, of the
inputs are "true."(1) The output is "false"(0) if both inputs are
"false"(0) or if both inputs are "true."(1) In other words, the output
is 0 if the inputs are the same, is 1 if the inputs are different.
Computer Organization and Architecture
Example:
Truth table
43
Example
Inputs Output
p Q R F
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
Look for cells where output F is ‗1‘. The corresponding min terms are
P‘QR, PQ‘R, PQR‘, PQR.By doing logical OR of these four min terms,
we will get the Boolean function of output F.
44
Computer Organization and Architecture
First, identify the Maxterms for which, the output variable is zero
and then do the logical ANDof those Maxterms to get the Boolean
expression function corresponding to that output variable
Repeat the same procedure for other output variables also if there
is more than one outputvariable.
Karnaugh map
45
Computer Organization and Architecture
Figure 1.20a shows the map of four squares for a function of two
variables.
Figure 1.20b shows the result for the truth table of Table 1.11.
In Figure 1.20d the two rows embraced by the symbol A are those
in which the variable A has the value 1; the rows not embraced by
the symbol A are those in which A is 0; similarly, for B,C, and D.
48
Computer Organization and Architecture
stored, and transmitted as groups ofbinary digits.
1. 9 KEY WORDS
3.Octal number system-In the octal number system, the base is 8 and it
uses numbers from 0 to 7 to represent numbers. Octal numbers are
commonly used in computer applications. Converting an octal number to
decimal is the same as decimal conversion and is explained below using
an example.
49
5.Hexadecimal number system-In the hexadecimal system, numbers are
written or represented with base 16. In the hexadecimal system, the
numbers are first represented just like in the decimal system, i.e. from 0 to
9. Then, the numbers are represented using the alphabet from A to F. The
below-given table shows the representation of numbers in the hexadecimal
number system.
52