Unit 2: Number Systems, Codes and Logic Functions
Unit 2: Number Systems, Codes and Logic Functions
Logic Functions
Introduction
Any positive integer b>1 can be chosen as the base for a positional
number system similar to the decimal system (b=10) or the binary
system (b=2). Such a system uses b symbols for the integers
0, 1, 2, 3, ..., b-1
N = an an-1... a1 a0
N = an × bn + an-1×bn-1 + ... + a2 × b2 + a1 × b1 + a0 × b0
17
Computer Basics
Decimal System
The powers of ten,
This decimal fraction is said to have three decimal places, the number of
digits to the right of the decimal point.
The place values in the binary system are the powers of the base b=2,
just as the place values in the decimal systems are the powers of ten.
18
Number Systems, Codes and Logic Functions
Specifically, the place values of the integral part of a binary number are
the nonnegative powers of two.
20 21 22 23 ...
and the place values of the fractional part of a binary number are the
negative powers of two,
Table 1.1.
2-4 0.0625
2-3 0.125
2-2 0.25
2-1 0.5
20 1
21 2
22 4
23 8
Since 8 = 23, each octal digit has a unique 3-bit binary representation,
given in Table 1.2.
Table 1.2
19
Computer Basics
The place values in the octal system are powers of 8; some of the these
powers appear in Table 1.3.
Table 1.3
20
Number Systems, Codes and Logic Functions
1. 7 Exercise
i) 2
ii) 8
iii) 10
iv) 16.
b. The place values of the fractional part of a binary number are the
i) nonnegative powers of 2
ii) negative powers of 2
iii) negative powers of 10
iv) negative powers of 8.
2. Analytical questions
21
Computer Basics
110101 = 1 × 25 + 1 × 24 + 0 × 23 + 1 × 22 + 0 × 21 + 1 × 20
Table 1.6 lists the binary representations of the integers from 0 to 25,
with the place of the bits shown at the top of the table. Sometimes a
subscript 2 is used to distinguish a binary number, e.g. one may write
1010112 if it is not clear from the context that 101011 is a binary number
rather than a decimal number. Also, for easier reading, one sometimes
separates a binary number into 4-bit groups, to the left and right of the
binary point; e.g.
22
Number Systems, Codes and Logic Functions
Table 1.6
Example 2.1:
Place values 25 24 23 22 21 20
Binary number 1 1 0 1 0 1
1
4
16
32
Decimal equivalent 53
23
Computer Basics
(b) To convert 101.11012 to its decimal equivalent, use Table 1.1 for
the decimal values of the negative powers of two
0.0625
0.25
0.5
1
4
Decimal equivalent 58125
.
2.3 Decimal-to-Binary Conversion
It is possible to find binary representation of a decimal number N by
converting its integral part (NI), and its fractional part (NF) separately. It
is illustrated with the decimal number N = 109.78125.
Example 2.2
The zero quotient indicates the end of the calculations. The sequence of
remainders from the bottom to up, as indicated by the arrow, yields the
required binary equivalent. That is NI = 109 = 11011012.
24
Number Systems, Codes and Logic Functions
Here stop when the quotient, 1, is less than the divisor 2, since this last
quotient will be next and last remainder. Again the arrow indicates the
sequence of bits that gives the binary equivalent of the number.
0.781 25
×2
1.562 50
×2
1.125 00
×2
0.250 00
×2
0.500 00
×2
1.000 00
It is found that the binary equivalents of the integral and fractional parts
of the decimal number N = 109.78125. The binary equivalent of N is
simply the sum of these two equivalents:
N = NI + NF = 1101101.11001
25
Computer Basics
Example 2.3 :
Let, N = 13.6875. Convert the integral part, NI = 13, and the fractional
part, NF = 0.6875, into binary forms :
2)13 0.6875
2)6 1 ×2
2)3 0 1.3750
1 1 ×2
0.7500
×2
1.5000
×2
1.0000
At this point in the procedure, one can again multiply 0.6 by 2. This
means the above four steps will be repeated again and again. That is,
(The number of bits which repeat is not always four; nor does the
repeating block necessarily begin at the binary point, it depends on the
given N.)
26
Number Systems, Codes and Logic Functions
Example 2.4 :
7
×16
112
+3
115
×16
1840
+13
1853
×16
29648
+5
29653 = 73D516
27
Computer Basics
0.78125 × 16 = 12.50000 12
0.50000 × 16 = 8.00000 8
N = P + Q = 25F7.C816
Hexadecimal-Binary Interconversion
Example 2.5 :
Hexadecimal-Binary Inter-
conversion
Convert to binary form (a) 3D5916, (b) 27.A3C16.
(a) 3D59
(b) 27.A3C
28
Number Systems, Codes and Logic Functions
Example 2.6 :
Partition each binary number into 4-bit blocks to the left and right of the
binary point adding 0s if necessary. Then replace each 4-bit block by its
equivalent hexadecimal digit (Table 1.4).
2D2E
1 C. B 6 C
2.5 Exercise
i) 8
ii) 10
iii) 12
iv) 14.
i) 15
ii) 18
iii) 22
iv) 24.
29
Computer Basics
i) 1001102
ii) 11110012
iii) 11011012
iv) 11101012.
i) 1719
ii) 9610
iii) 9719
iv) 09919.
2. Analytical questions
i) 101012
ii) 1001012
iii) 1011.1012
iv) 101.11012.
i) 653.625
ii) 13.6875
iii) 367
iv) 235.07.
i) 129A.B8616
ii) 73D516
iii) 0.782516
iv) 39.C816.
i) 129A.B8616
ii) 3D5916.
i) 101101001011102
ii) 101101101110.10001102.
30
Number Systems, Codes and Logic Functions
Binary Addition Step 2. Record the unit digit of the column sum. If the sum exceeds
one, carry the two's digit 1, to the next column.
The addition table for the binary digits 0 and 1 appears as Table 1.7 the
only additional facts needed for binary addition appear in Table 1.8.
+ 0 1 0+0=0
0 0 1 0+1=1
1 1 10 1+0=1
1 + 1 = 0, with a carry of 1
1 + 1 + 1 = 1, with a carry of 1
Table 1.7 Binary Addition
Table 1.8 Binary Addition Facts
Example 3.1 :
31
Computer Basics
STEP 3: 1 + 0 =1.
STEP 2.
111 Carries
111 Addend
+101 Augend
1100 Sum
Step 3. Stop.
Example 3.4 :
1101011
× 10110
0000000
1101011
1101011
0000000
1101011
Then add the five bottom rows of numbers. In actual practice, one does
not write down any zero products. Finally bring down initial zero, if any
and form a running total, adding one nonzero row after another :
32
Number Systems, Codes and Logic Functions
Binary Subtraction Step 1. If the lower (subtrahend) digit is greater than the upper
(minuend) digit, borrow from the next column to the left.
The only subtraction facts needed for binary subtraction are the four
listed in Table 1.9.
10 - 1 = 1
Example 3.5 :
11101
- 1011
10010
33
Computer Basics
Example 3.6 :
Obtain,
011
11000
- 10011
101
Example 3.7 :
00110 01
1100101001
- 110110110
101110011
Example 3.8 :
Calculate 42558 ÷ 123. Here 123 is the divisor. The algorithm for
division yields :
34
Number Systems, Codes and Logic Functions
346
123)42558
369
565
492
738
738
0
That is, multiply 123 by 3 and subtract the product, from 425; then
multiply 123 by 4 and subtract the product 492, from 565; lastly multiply
123 by 6 and subtract the product 738, from 738, to obtain a 0
remainder. [Because of the geometry of the scheme, what these steps
actually accomplish is first to subtract 3 × 102 times the divisor from the
dividend, then 4 × 10 times the divisor from what is left, and then 6
times the divisor from what is left. At that point the dividend is
exhausted, showing that the dividend originally contained the divisor
3 ×102 + 4 × 10 + 6 =346 times].
The above algorithm also works for binary division. In fact, multiplying
the divisor by the only nonzero digit, 1, does not change the number;
hence the algorithm for division reduces to repeated subtraction of the
divisor (times a power of 2).
Example 3.9 :
11011
11)1010001
11
100
11
100
11
11
11
0
Thus the quotient is 11011.
35
Computer Basics
Example 3.10 :
1101
1001)1110111
1001
1011
1001
1011
1001
10
3.5 Complements
There are two types of complements, the one's complement and two's
complement, respectively.
Example 3.11 :
36
Number Systems, Codes and Logic Functions
Observe that taking the ones complement simply inverts each digit, i.e. 0
is replaced by 1 and 1 is replaced by 0.
Example 3.12 :
011
11110000 B
-10001110 A
01100010 Y
Observe that the borrowing was propagated to the third digit to the left.
11110000 B
+ 01110001 One's complement of A
01100001
1
01100010
11110000 B
+01110010 Two's complement of A
01100010
Deleting the 1 (which would be an overflow in an 8-bit register) gives
the difference Y.
37
Computer Basics
3.6 Exercise
i) 2 step algorithm
ii) 3 step algorithm
iii) 4 step algorithm
iv) 5 step algorithm.
i) addition
ii) subtraction
iii) multiplication
iv) conversion.
2. Analytical questions
i) 10010 - 11011
ii) 10101 - 00110
iii)11101 - 1011.
i) 11010011 ÷ 11
ii) 11110111 ÷ 1001.
38
Number Systems, Codes and Logic Functions
i) 1011012
ii) 1111000011112
iii) 909010
iv) 10101012.
i)11011 - 10010
ii)10001110 - 11110000
iii) 10101 - 00110.
39
Computer Basics
Information is data which has been converted into a more useful form,
i.e. processed facts. For example: total price = unit price × quantity sold.
Data Information and Codes Here total price is information and unit price, quantity sold are data.
Examples are: pay slips, receipts, reports.
‘Codes’ are used to reduce the volume of data. The recording of data can
be made less laborious, less prone to error and the data will subsequently
be more manageable and easier to manipulate if standard abbreviations
or simplified representations are used. This technique is called data
coding. Examples: Yes/No answers on forms can be represented by
single Y’s or N’s. A person's sex may be indicated by M or F.
Here discussion will be on how numeric data are represented inside the
computer using straight binary coding, which encodes an entire number
as a whole. Straight binary coding requires that numbers be stored in
computer locations as a fixed number of bits. A list of bits so treated as a
unit is called a word, and the number of bits is called the length of the
word. For definiteness, assume, unless otherwise stated, that computers
have words of fixed length 32.
Integers Representation
40
Number Systems, Codes and Logic Functions
423 0 0 0 0 0 ... 0 0 1 1 0 1 0 0 1 1 1
-423 1 1 1 1 1 ... 1 1 0 0 1 0 1 1 0 0 1
In the first display the dots represent omitted 0s; in the second omitted
1's.
0 1 1 1 1 ... 1 1 1 1 1
31 ones
41
Computer Basics
Table 1.10
Floating-Point Representation
Figure 4.1
Table 1.11
True Exponent -64 -63 -62 -61 ... -1 0 1 ... 63
Characteristic 0 1 2 3 ... 63 64 65 ... 127
42
Number Systems, Codes and Logic Functions
Example 4.2 :
Characteristics Mantissa
1 1 0 0 1 0 0 1 1 1 0 1 0 0 0 1 1 1 1 0 1 0 0 0 ... 0 0
Sign bit
Observe that (i) the first bit is 1, which indicates that A is negative; (ii)
the first characteristic field is 1, which indicates that the exponent of A
is nonnegative; and (iii) sufficiently many 0s are attached to the end of
the mantissa of A to complete the 24-bit mantissa field.
There are many ways of representing numerical data in binary form. One
way is simply to write the numbers to the base 2. This is called straight
BCD Code binary coding. Another way is to encode decimal digits. These code,
which require 4 bits for each decimal digit, is called BCD (binary-coded
decimal) code.
Table 1.12
Decimal BCD
Digits Code
8-4-2-1
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
4-bit BCD words are shown in Table 1.12. The first one is a weighted
code, in which the bits are given, from left to right, the weights 8, 4, 2,
43
Computer Basics
and 1, respectively. Since these weights are just the place valves in the
binary system, a decimal digit is encoded as its binary representation.
Example 4.3 :
4 6 9
0100 0110 1001
N =1110101012
4.5 Parity
For each character, the value of the check bit (0 or 1) is such as to make
the sum of the bits, including the check bit, odd or even, according as the
machine operates on odd or even parity.
Example 4.4 :
Parity If the computer uses odd parity, the characters 7, 9 are stored as follows:
That is, the check bit for 7 is 0 because the sum of the odd bits in the 6-
bit code for 7 is three, which is already odd. On the other hand, the
check bit for 9 is 1 because the sum of the bits in the 6-bit code for 9 is
two which is even.
The purpose of the check bit is to ensure that no bit is lost or gained
when data are transmitted internally in a computer. After a character is
transmitted, the computer adds up the bits in the character. If a single
error occurs, the sum of the bits will not have the same parity as the
parity of the computer. The computer would then retransmit the data.
Clearly, the computer cannot use this type of checking to see if two
errors occurred; but such an occurrence is very unlikely.
44
Number Systems, Codes and Logic Functions
More generally, the word ‘byte’ is used to denote any group of eight bits.
It is seen that a byte may be represented by two hexadecimal digits, the
first corresponding to the zone bits and the second to the numeric bits.
As with the 4- and 6-bit BCD codes, an extra, check bit is utilized in the
computer.
There are two 8-bit BCD code predominant in the computer industry
today. EBCDIC, pronounced ‘ebb-see-dick’ and is short for Extended
Binary-Coded Decimal Interchange Code. This code developed by IBM,
is used mainly by IBM-compatible computer systems (Table 1.13).
ASCII pronounced 'ass-key' and is short for American Standard Code for
Information Interchange. This code was originally developed as a 7-bit
standardization of various special codes, and was then extended to an 8-
bit code. It is used mainly by non-IBM computer systems (Table 1.14).
45
Computer Basics
Table 1.14
Char. Zone Numeric Hex Char. Zone Numeric Hex Char. Zone Numeric He
x
0 0101 0000 50 A 1010 0001 A1 P 1011 0000 B0
1 0001 51 B 0010 A2 Q 0001 B1
2 0010 52 C 0011 A3 R 0010 B2
3 0011 53 D 0100 A4 S 0011 B3
4 0100 54 E 0101 A5 T 0100 B4
5 0101 55 F 0110 A6 U 0101 B5
6 0110 56 G 0111 A7 V 0110 B6
7 0111 57 H 1000 A8 W 0111 B7
8 1000 58 I 1001 A9 X 1000 B8
9 0101 1001 59 J 1010 AA Y 1001 B9
K 1011 AB Z 1011 1011 BA
L 1100 AC
M 1101 AD
N 1110 AE
O 1010 1111 AF
4.7 Exercise
2. Analytical questions
46
Number Systems, Codes and Logic Functions
5.2 Introduction
Pulses of electricity are called digital signals. A digital signal has two
discrete levels or values. The two discrete signal levels HIGH and LOW
can also be represented by binary digits 1 and 0 respectively. A binary
digit (0 or 1) is referred to as a bit. Since a digital signal can have only
one of the two possible levels 1 or 0, the binary number system can be
used for the analysis and design of digital systems. The two levels (or
states) can also be designated as on and off (or TRUE and FALSE).
George Boole introduced the concept of binary number system in the
studies of this mathematical theory of LOGIC in the Laws of Thought in
1854 and developed its algebra known as Boolean Algebra.
OR Gate
An OR gate has an output 1 if any of its inputs are 1. The diagram and
OR Gate truth table for two input OR gate are shown in Fig 5.1. Ideal output, Y =
A + B, where + denotes OR operation.
47
Computer Basics
(a) A
B ) Y
Truth Table
(b)
A B Y
0 0 0
0 1 1
1 0 1
1 1 1
Figure 5.2 Illustrates, the close relationship between 2-input OR gate and
electrical switching circuits. Such a circuit normally contains some
source of energy (a battery), an output device (a lamp), and one or more
switches - all connected by wires. A switch is a two-state device that is
either closed (on) or open (off). In Figure 5.2 switch A and B, are
connected in parallel. The lamp will light if switch A is closed, or if
switch B is closed, or if both switches are closed. But this is the property
described by the truth table for the OR gate, where 1 denotes that the
switches or lamp is on and 0 indicates that it is off.
AO
B O
Switches
Battery Lamp
AND Gate
An AND gate has an output 1 if all of its inputs are 1. The diagram and
truth table for a two input AND gate are shown in Figure 5.3. Here
AND Gate output, Y= A.B, where '.' denotes AND operation.
(a) A
Y = A.B
B
48
Number Systems, Codes and Logic Functions
A B Y
0 0 0
0 1 0
1 0 0
1 1 1
Figure 5.3: Two-input AND gate (a) symbol, (b) truth table.
o o
A B
Battery Lamp
NOT Gate
A NOT gate has one input and one output. It has the effect of reversing
the input signal and is sometimes called an inverter. The diagram and
NOT Gate truth table for a NOT gate are shown in Fig 5.5. Here output Y= A
where '-' indicates NOT operation.
(a) A O Y=A
Truth Table
(b)
A Y
0 1
1 0
49
Computer Basics
Some secondary gates are NAND, NOR, EXOR etc. NAND and NOR
gates are called universal gates because any one them can be used to
Secondary Logic Gates realize of any logic expression.
NAND Gate
A NAND gate has the same effect as an AND gate followed by a NOT
gate. Hence the output will be opposite of the AND gate. The diagram
NAND Gate and truth table for a two-input NAND gate are shown in Figure 5.6.
(a) A
B O Y=A.B
A B Y
0 0 1
0 1 1
1 0 1
1 1 0
NOR Gate
A NOR gate has the same effect as OR gate followed by a NOT gate.
Hence the output will be the opposite of OR gate. The diagram and truth
NOR Gate table for a two-input NOR gate are shown in Figure 5.7.
(a) A
B ) o Y = (A + B)
A B Y
0 0 1
0 1 0
1 0 0
1 1 0
50
Number Systems, Codes and Logic Functions
EXOR Gate
(a) A
B )) Y=A⊕B
A B Y
0 0 0
0 1 1
1 0 1
1 1 0
Basic gates (AND, OR, NOT) and universal gates (NAND, NOR) can be
used in combination to make up digital computer circuits.
51
Computer Basics
5.5 Exercise
1. Multiple choice questions
B. Analytical questions
52
Number Systems, Codes and Logic Functions
53