0% found this document useful (0 votes)
76 views17 pages

Chapter 4

The document discusses different number systems used in computing including binary, octal, decimal, and hexadecimal. It provides examples of numbers in each system and methods for converting between the systems. The key number systems covered are binary (base 2), octal (base 8), decimal (base 10), and hexadecimal (base 16). Conversion methods include splitting into place values and replacing digits with their equivalent values in the target system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views17 pages

Chapter 4

The document discusses different number systems used in computing including binary, octal, decimal, and hexadecimal. It provides examples of numbers in each system and methods for converting between the systems. The key number systems covered are binary (base 2), octal (base 8), decimal (base 10), and hexadecimal (base 16). Conversion methods include splitting into place values and replacing digits with their equivalent values in the target system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Chapter 4

Computer arithmetic, coding systems, and


logic gates
4.1 Number systems
A number system is a group of symbols used to represent numbers. The
following number systems are closely associated with computers: binary system,
octal system, decimal system, and hexadecimal system.
1. Binary system
This is a number system that consists of only two digits: 0 and 1. The binary
system is also called the base 2 number system. Examples pf binary numbers
are: 00112, 0102, and 11001102.
2. Octal system
It is a number system that consists of eight digits: 0, 1, 2, 3, 4, 5, 6, and 7.
The octal system is also called the base 8 number system. Examples of octal
numbers are: 5648, 5708, and 1458.
3. Decimal system
It is a number system that consists of ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
The decimal system is also called the denary system or base 10 number
system. Examples of decimal numbers are: 987, 45, and 19803.
4. Hexadecimal system
It is a number system that consist of sixteen digits: 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. This system is also called base 16
number system. Examples of hexadecimal numbers are: E2516, AD316, and
B42D16.

4.2 Conversion of numbers


1. Converting from binary to decimal numbers
To change a binary number to decimal, we simply multiply the various digits
by their appropriate place values and then add the results.

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

116 = 11101002 116 = 10001002

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. Converting from hexadecimal to binary numbers


To change a hexadecimal number to binary, we simply replace each digit of the
hexadecimal number with its base 2 equivalent.
Example
Convert 15C16 to base 2.
Solution
15C16 = 00001 0101 1100
= 00001010111002
Exercise
Convert to base 2:
1. BD416 3. 8F316
2. 26E16 4. A5416
Assignment
1. Convert to base 16: 2. Convert to base 2:
a. 10011010012 a. 23716
b. 11000100112 b. 48B16
c. 1010011102 c. F3516
7. Converting from octal to decimal numbers
To change an octal number to base 10, we simply multiply the various digits by
their appropriate place values and add the results.
Example
Convert 3578 to decimal.
Solution

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

4.3 Binary addition and subtraction


In the addition and subtraction of binary numbers, only the binary digits 0 and 1
are used.
Example 1
Add 1112 and 1112
Solution
1 1
1 11 12
+ 1 1 12
1 1 1 02
Exercise
1. 10102 + 112 3. 10112 + 11012
2. 10110112 + 1110102 4. 11112 + 1112
Example 2
1012 – 112
Solution
0 2
1 0 12
- 1 12
1 02
Exercise

9
1. 10110112 – 1110102 3. 11012 – 10102
2. 110002 – 112 4. 11002 - 1112

4.4 Data representation


To understand how a computer processes data, it is important to know how it
represents data. People communicate through speech by combining words into
sentences. Most computers are digital; they recognize only two discrete states:
off and on. The two digits 0 and 1 represent these states respectively.
People count by using digits in the decimal system (0 through 9). The computer,
however, uses the binary system because it recognizes only two states. The
binary system consists of only two digits: 0 and 1, called bits. A bit is the
smallest unit of data a computer can process and store.
Eight bits make one byte, and a byte is equal to a character. A byte provides
enough different combinations of 0s and 1s to represent 256 different characters.
A character can be a letter of the alphabet, a number, a symbol, a punctuation
mark, a blank space, etc. A computer can represent four types of characters:
a) Alphanumeric characters (letters A-Z, a-z, and the digits 0-9).
b) Punctuation marks and other symbols (, . ; @ # $ % &).
c) Graphical characters.
d) Control characters such as [Esc], [space], [Alt], and [Ctrl].

4.5 Coding schemes


The combinations of 0s and 1s that represent characters are defined by patterns
called coding schemes. In a coding scheme, every character is represented by a
combination of bits that is different from any other combination. Some types of
coding schemes are ASCII, EBCDIC, BCD, and Unicode.
a) American Standard Code for Information Interchange (ASCII)
It is a 7-bit code standard for representing characters, symbols, and numbers.
It is the most widely used coding scheme to represent data in most personal
computers (PCs). There are 128 standard ASCII codes, which can be
represented by a 7-digit binary number (from 0000000 to 1111111). For
example, the ASCII code for the letter H is 1001000.
The standard ASCII character set uses just 7 bits to represent each character.
However, there are some larger character sets e.g., the extended ASCII
character set, that uses 8 bits, giving additional 128 codes. The extra codes

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.

4.6 Logic gates


a) Logic signals
Computers are digital devices; they recognize only two discrete states: on
and off. The two digits, 0 and 1, can easily represent these two states. The
digit 0 represents the off state, and the digit 1 represents the on state.
b) Operations on logic signals
Let us assume that we have two logic signals, A and B, which form an input
set to a circuit that takes two logic signals as input, and has an output that is
also a logic signal. This situation is represented in figure 4.3 below.

The output, X, depends on the inputs, A and B. X is a logical function of A and


B. We will examine a few basic logic functions: the AND, OR and NOT
functions or logic gates.
c) Logic functions or logic gates
Digital systems are constructed using logic gates. Most logic gates have two
inputs and one output. Examples of logic gates are the AND, OR, NOT,
NAND, NOR, XOR, and EXNOR gates. The basic operations are described

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.

iii. The NOT gate:


It is an electronic circuit that produces an inverted version of the input as
its output. It is also called an inverter. If the input variable is A, then the
inverted output is NOT A. This is also known as A1 or A.

Figure 4.4 Basic logic gates


d) Other logic gates

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.

The truth table for the NOR gate is shown below.

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

You might also like