Chapter 4
Chapter 4
1
Examples
Find the decimal equivalent of the following binary numbers:
1. 10012 2. 111012
Solution
1. 10012 = (1x23) + (0x22) + (0x21) + (1x20)
= (1x8) + (0x4) + (0x2) + (1x1)
=8+0+0+1
=9
2. 111012 = (1x24) + (1x23) + (10x22) + (0x21) + (1x20)
= (1x16) + (1x8) + (1x4) + (0x2) + (1x1)
= 16 + 8 + 4 + 0 + 1
= 29
Exercise
Find the decimal equivalent of the following binary numbers:
1. 101012 2. 11012 3. 110102
2. Converting from decimal to binary numbers
To change a decimal number to binary, we divide the number by 2 and write
down the remainder. We continue dividing until the result is zero. We then
read the sequence of remainders from bottom to top to get the corresponding
binary number.
Examples
Convert 116 and 69 to base 2.
Solution
2 69
116
2 58 0
2 29 0
2 14 1
2 7 0
2 3 1
2 1 1
2 0 1
2
2 34 1
2
2 17 0
2 8 1
2 4 0
2 2 0
2 1 0
2 0 1
Exercise
Convert to binary:
1) 99 2) 23 3) 38
Assignment
1. Convert to base 10: 3. Convert to base 2:
a. 1110112 a. 53
b. 110012 b. 34
c. 10112 c. 41
3. Converting from binary to octal numbers
To change a binary number to octal, we split the digits in the binary number
into groups of 3 digits from right to left and replace them with their
corresponding octal digits.
Binary Octal
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7
Figure 4.1 Calculator table
Examples
1. Convert 1011000000012 to base 8.
3
2. Convert 101100112 to base 8.
Solution
1. 1011000000012 = 101 100 000 110
= 5 4 0 1
= 54018
2. 101100112 = 010 110 011
= 2 6 3
= 2638
Exercise
Convert to base 8:
1. 1010001112 2. 110011002 = 3. 1011101100
= 5078 3148 12 = 27318
4. Converting from octal to binary numbers
To change an octal number to binary, we simply replace each digit of the
octal number with its binary equivalent.
Example
Convert 5368 to base 2.
Solution
5368 = 101 011 110
= 1010111102
Exercise
Convert to base 2:
1. 4178 3. 7618
2. 5028 4. 7028
Assignment
1. Convert to base 8: 2. Convert to base 2:
a. 111010102 a. 5318
b. 1001110112 b. 3708
c. 10112 c. 2478
4
5. Converting from binary to hexadecimal numbers
To change a binary number to hexadecimal, we split the digits in the binary
number into groups of 4 bits from right to left and replace them with their
corresponding hexadecimal digits.
Binary Hexadecimal
0000 0
0001 1
0010 2
011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
Figure 4.2 Calculator table
Examples
1. Convert 1011110101002 to base 16.
2. Convert 10011011102 to base 16.
Solution
1. 1011110101002 = 1011 1101 0100
= B D 4
= BD416
2. 10011011102 = 0010 0110 1110
= 2 6 E
= 26E16
5
Exercise
Convert to base 16:
1. 110111101002
2. 100011010000100002
3. 1110101111000112
6
3578 = (3x82) + (5x81) + (7x80)
= (3x64) + (5x8) + (7x1)
= 192 + 40 + 7
= 239
Exercise
Find the decimal equivalent of the following octal numbers:
1. 6248 3. 3208
2. 1468 4. 4278
8. Converting from hexadecimal to decimal numbers
Remember that hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,
and F. A, B, C, D, E, and F represent 10, 11, 12, 13, 14, and 15 respectively on
the decimal system. To change a hexadecimal number to base 10, we simply
multiply the various digits by their appropriate place values and add the results.
Examples
Convert to decimal:
1. AE2416 2. BF916
Solution
1. AE2416 = (Ax163) + (Ex162) + (2x161) + (4x160)
= (10x163) + (14x162) + (2x161) + (4x160)
= (10x4096) + (14x256) + (2x16) + (4x1)
= 40960 + 3584 + 32 + 4
= 44,580
2. BF916 = (Bx162) + (Fx161) + (9x160)
= (11x162) + (15x161) + (9x160)
= (11x256) + (15x16) + (9x1)
= 2816 + 240 + 9
= 3065
Exercise
Convert to base 10:
1. 1C316 3. A1216
2. 26416 4. DB416
7
9. Converting from hexadecimal numbers to base 8
To convert from hexadecimal to base 8, we first convert the hexadecimal
number to its binary equivalent. We then divide the digits in the binary number
into groups of 3 digits from right to left and replace them with their
corresponding octal digits.
Example
Convert AB0116 to base 8.
Solution
ABO116 = A B 0 1
= 1010 1011 0000 0001
= 10101011000000012
= 001 010 101 100 000 001
= 1 2 5 4 0 1
= 1254018
Exercise
Convert to base 8:
1. A5416 3. 8E316
2. B42D16 4. 26E16
10.Converting from octal numbers to base 16
To convert from octal to base 16, we first convert the octal number to its binary
equivalent. We then divide the digits in the binary number into groups of 4
digits from right to left and replace them with their corresponding hexadecimal
digits.
Example
Convert 1254018 to base 16.
Solution
1254018 = 1 2 5 4 0 1
= 001 010 101 100 000 001
8
= 0010101011000000012
= 1010 1011 0000 0001
= A B 0 1
= AB0116
Exercise
Convert to base 16:
1. 3428 3. 5638
2. 7048 4. 2468
9
1. 10110112 – 1110102 3. 11012 – 10102
2. 110002 – 112 4. 11002 - 1112
10
are used to represent nom-English characters (e.g., é, ç), graphic symbols,
and mathematical symbols (+, -, /, x).
b) Extended Binary Coded Decimal Interchange Code (EBCDIC)
It is an 8-bit coding scheme used to represent 256 characters. It is used
primarily in supercomputers, mainframe computers, and minicomputers. On
the other hand, ASCII is used in microcomputers.
The EBCDIC scheme, like the extended ASCII scheme, is used to represent
256 different characters, but the characters are represented differently in the
two schemes.
c) Binary Coded Decimal (BCD)
It is a coding scheme in which each decimal digit (0-9) is presented by 4 bits.
One advantage of BCD is that there is no limit to the size of a number. To
add another digit to a number, you just need to add a new 4-bit sequence.
Decimal
number
0 1 2 3 4 5 6 7 8 9
BCD 000 010 100
code
0001 0010 0011 0101 0110 0111 1001
0 0 0
Example
What is the BCD representation of 784?
Solution
7 8 4
0111 1000 0100
784 is represented as 011110000100
d) Unicode
The ASCII and EBCDIC coding schemes are used for the English language
and Western European languages, but are not large enough for Asian
languages that use different alphabets.
Unicode is a 16-bit coding scheme that can represent over 65,000 characters.
It can be used to represent almost all of the world’s current written
languages.
Parity
11
No matter the coding scheme used to represent characters in the computer, it
is important that the computer stores data accurately. For each combination
of bits used to represent a character, the computer adds at least one extra bit,
called a parity bit, used for error checking. Foe example, a computer that
uses an 8-bit code – such as EBCDIC or extended ASCII – will have a ninth
bit for parity checking. A parity bit can detect if one of the bits in a byte has
been changed accidentally. Such errors, however, are very rare (since most
computers never have a parity error during their lifetime) and can occur due
to voltage fluctuations, static electricity, or memory failure. The test for bit
count is called a parity check.
12
below with the aid of truth tables. A truth table is a chart of 0s and 1s
arranged to represent the output of all inputs.
i. The AND gate:
It is an electronic circuit that gives a high output (1) only if all its inputs
are high (1); else, it gives a low output (0). A dot (.) is used to show the
AND operation, i.e., A.B. Note that this dot is sometimes omitted, i.e.,
AB.
ii. The OR gate:
It is an electronic circuit that gives a high output if one or more of its
inputs are high; else, it gives a low output. A plus (+) is used to show the
OR operation, i.e., A+B.
13
Four other logic gates can be made from the basic gates. They are the
NAND, NOR, Exclusive-OR, and Exclusive-NOR gates. We shall study the
first three.
i. The NAND gate:
It is formed by connecting an AND gate to an inverter. The Boolean
expression for the NAND gate is AB.
From the above table, it can be seen that the unique output of the NAND gate is
low if both inputs are high; else, the output id high.
ii. The NOR gate
It is formed by connecting an OR gate to an inverter. The Boolean
expression for the NOR gate is A+B.
14
From the above table, it can be seen that the unique output of the NOR
gate is high if both inputs are low; else, the output is low.
iii. The Exclusive-OR gate (XOR gate)
This gate may be referred to as “any but not all,” i.e., the unique output is high if
only one or the other input is high. In other words, the output is high if the
inputs are different, and it is low if the inputs are the same. The Boolean
expression for the XOR gate is X = AB+AB.
The logic circuit and truth table for the XOR gate are shown below.
15
Facing the GCE
1. Showing clearly all necessary steps, convert:
a) The hexadecimal number DC to octal. (4 marks)
b) The binary number 10011101 to decimal. (4 marks)
(GCE 2018)
2. Given the following Boolean equation: Z = A .B + A. B
a) Draw the Boolean circuit. (3 marks)
b) Complete the corresponding truth table below. (5 marks)
A B A B A .B A. B Z
0 0
0 1
1 0
1 1
(GCE 2015)
Assignment
Answer the following questions:
1. GCE 2016: Q4 d. 2. GCE 2017: Q4 a
16
17