Chapter 1
Number Systems
The numbering system we all use and is familiar to all of us is the decimal or denary(base 10)
number system. This uses digits 0 to 9 which are placed in weighted columns.
10000 1000 100 10 Units
3 1 4 2 1
The denary number represented above is thirty-one, four hundred and twenty-one.
1*10
500
102 101 100
Binary Numbering system
Numbering system used by computers consisting of 0 and 1(base 2). Since computers contain
millions and millions of tiny ‘switiches’, which must be in the ON and off position. A switch in
the ON position can be represented by 1 and in the OFF position can be represented by 0. Each
of the binary digits are known as bits.
150
10010110
Converting from binary to denary and from denary to binary
Each time a 1 appears in a column, the column value is added to the total. For example, the
binary number above is:
1 1 1 0 1 1 1 0
128+64+32+8+4+2=238(denary)
238-128=110
110-64=46
46-32=14
14-8=6
6-4=2
2-2=0
Method 1
This method involves placing 1s in the appropriate position so that the total equates to 107.
128 64 32 16 8 4 2 1
0 1 1 0 1 0 1 1
Method 2
This method involves successive division by 2; the remainders are then written from bottom to
top to give the binary value.
107/2=53.5 0.5*2=1
Exercises
1. Convert these binary numbers into denary.
a) 00110011
b) 10011001
c) 11111111
2. Convert the following denary into binary.
a) 41
00101001
b) 127
01111111
Binary addition and subtraction
The previous examples were all positive. There are a number of ways to represent positive and
negative numbers:
One’s complement
Two’s complement
One’s complement
Each digit in the binary number is inverted(0 becomes 1, and 1 becomes 0).
Example:
01011010(denary value 90) becomes 10100101(denary value -90)
Two’s complement
Each digit in the binary number is inverted and a ‘1’ is added to the right most bit.
Example:
01011010 becomes:
-80
0101000
1010111
+ 1
1011000
We will only be using second complement to represent negative numbers in binary. The two’s
complement uses these weightings for an 8-bit number representation:
-128 64 32 16 8 4 2 1
This means
-128 64 32 16 8 4 2 1
1 1 0 1 1 0 1 0
This is equivalent to -128+64+16+8+2=-38
-128 64 32 16 8 4 2 1
0 0 1 0 0 1 1 0
This is equivalent 32+4+2=38
Find the binary value for -104 using two’s complement:
128 64 32 16 8 4 2 1
0 1101000 (+104)
Invert the digits: 1 0 0 1 0 1 1 1 (+104 in denary)
Add 1: 1
Which gives: 1 0 0 1 1 0 0 0 (-104 in denary)
Exercise
Convert these denary numbers into 8-bit binary numbers using two’s complement where
necessary. Use these binary column weightings:
-128 64 32 16 8 4 2 1
a) +114 0 1110010
-114 10001110
b) -14 11110010
00001110
11110010
c) -116 10001100
-128 64 32 16 8 4 2 1
10001100
Binary addition
a) 00100101(37 in denary) + 00111010(58 in denary)
b) 01010010(82 in denary) and 01000101(69 in denary)
Binary subtraction
1. Carry out the subtraction 95-68 in binary.
Second complement of this number 1000000
01111111
+ 1
10000000
2. Carry out the subtraction 49-80 in binary.
Exercise
Carry out these binary additions and subtractions using these 8-bit column weightings:
-128 64 32 16 8 4 2 1
a) 00110100 – 01000100 (68)
00110100 32+16+2=52
+10111100 -128+32+16+8+4=-68
11110000 -128+64+32+16=-16
b) 10111111- 11000011
10111111(-65)
00111101(61)
1111110 0(-128+64+32+16+8+4)=-4
Measurement of the size of computer memories
Byte is the smallest of memory in a computer.
Some computers use larger bytes such as 16-bit systems and 32-bit systems(multiples of 8
only).
The system shown above refers to some storage devices but is in accurate as it is based on the
base 10 system units where 1 kilo is equal to 1000. A 1 TB hard disk would allow the storage
1*1012 according to this system. However, memory size is actually measured in terms of powers
of 2 in computers, so another system has been proposed by the International Electrotechnical
Commission(IEC).
Hexadecimal number system
The hexadecimal system is very closely related to the binary system. Hexadecimal (sometimes
referred to as simply hex) is a base 16 system with the weightings:
104875 65536 4096 256 16 1
(165) (164) (163) (162) (161) (160)
Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters A to F are
used to represent hexadecimal digits.
A=10, B=11, C=12, D=13, E=14 and F=15.
16=24, four binary digits are equivalent to each hexadecimal digit.
Converting from binary to hexadecimal and from hexadecimal to binary
1. Starting from the right and moving left, split the binary number into groups of 4 bits.
2. If the last group has less than 4 bits, then simply fill in with 0s from left.
3. Take each group of 4 bits and convert it into the equivalent hexadecimal digit using the
previous table.
Example 1
Convert 1 0 1 1 1 1 1 0 0 0 0 1 from binary to hexadecimal.
Example 2
Convert 1 0 0 0 0 1 1 1 1 1 1 1 0 1 from binary to hexadecimal.
Activity
Convert these binary numbers into hexadecimal.
a) 1100011
0110 0011
63
b) 10011111111
1001 1111 1111
9FF
Converting from hexadecimal to binary
Using the above table, simply take each hexadecimal digit and write down the 4 bit code which
corresponds to the digit.
Example 1
Convert this hexadecimal number to its binary equivalent.
45A
8421
0100
0101
1010
Example 2
Convert this hexadecimal number to its binary equivalent.
B F 0 8
Use of the hexadecimal system
Memory dumps
Contents of a computer memory output to screen or printer.
It is much easier to work with Hexadecimal than to work with:
B5A41AFC
than it is to work with:
10110101101001000001101011111100
So, hexadecimal is often used when developing new software or when trying to trace errors in
programs.
A program developer can look at each of the hexadecimal codes (as shown in Table 1.4) and
determine where the error lies.
The value on the far left shows the memory location, so it is possible to find out exactly
where in memory the fault occurs.
Using hexadecimal is more manageable than binary.
It is a powerful fault-tracing tool, but requires considerable knowledge of computer
architecture to be able to interpret the results.
Exercise
Convert these hexadecimal numbers into binary.
a) A8 10100100
b) 9C6 100111000110
Binary-coded decimal (BCD) system
The binary-coded decimal (BCD) system uses a 4-bit code to represent each denary digit:
Therefore, the denary number 3 1 6 5 would be 0 0 1 1 0 0 0 1 0 1 1 0 0 1 0 1 in BCD format. The
4-bit code can be stored in the computer either as half a byte or two 4-bit codes stored together
to form one byte. For example, using 3 1 6 5 again …
Activity
1. Convert the denary numbers into BCD format.
a) 271 001001110001
b) 7991 0111100110010001
2. Convert these BCD numbers into denary numbers.
a) 100100110111
937
b) 0111011101100010
7762
Uses of BCD
The most obvious use of BCD is in the representation of digits on a calculator or clock display.
It is nearly impossible to represent decimal values exactly in computer memories which use the
binary number system. Normally this doesn’t cause a major issue since the differences can be
dealt with. However, sometimes exact values need to be stored to prevent significant errors
from accumulating for example in accounting.
Consider adding $0.37 and $0.94 together using fixed-point decimals.
Using binary addition, this sum will produce: 0 0 0 0 0 0 0 0 . 1 1 0 0 1 0 1 1 which produces 1 1
0 0 (denary 12) and 1 0 1 1 (denary 11), which is clearly incorrect. The problem was caused by 3
+ 9 = 12 and 7 + 4 = 11, as neither 12 nor 11 are single denary digits. The solution to this
problem, enabling the computer to store monetary values accurately, is to add 0 1 1 0 (denary
6) whenever such a problem arises. The computer can be programmed to recognise this issue
and add 0 1 1 0 at each appropriate point.
If we look at the example again, we can add .07 and .04 (the two digits in the second decimal
place) first.
1
0.37 7+4=11
0.94 3+9=12
1.31
Activity
Carry out these BCD additions
a) 0.45+0.21
0.45 0.01001001
0.21 0.00100001
0.66 0.10101010
b) 0.66+0.51
0.66 0.01100110
0.51 0.01010001
6+1 0111
6+5 1011
+6 0110
10001
1.00010111
1.17
c) 0.88+0.75
Character set
A list of characters that have been defined by computer hardware and software. It is necessary
to have a method of coding, so that the computer can understand human characters.
ASCII codes and Unicodes
The ASCII code system (American Standard Code for Information Interchange) was set up in
1963 for use in communication systems and computer systems.
The newer version of the code was published in 1986.
The standard ASCII code character set consists of 7-bit codes (0 to 127 denary or 0 to 7F in
hexadecimal); this represents the letters, numbers and characters found on a standard
keyboard together with 32 control codes (which use up codes 0 to 31 (denary) or 0 to 19
(hexadecimal)).
Storage of upper and lower case letters
Sixth bit changes from 1 to 0 when comparing lower and uppercase characters.
Extended ASCII uses 8-bit codes (128 to 255 in denary or 80 to FF in hex). This allows for
nonEnglish characters and for drawing characters to be included.
Since ASCII code has a number of disadvantages and is unsuitable for some purposes,
different methods of coding have been developed over the years such as Unicode.
Unicode
Unicode allows characters in a code form to represent all languages of the world, thus
supporting many operating systems, search engines and internet browsers used globally.
There is overlap with standard ASCII code, since the first 128 (English) characters are the
same, but Unicode can support several thousand different characters in total.
ASCII uses one byte to represent a character, whereas Unicode will support up to four bytes
per character.
It covers all languages and all writing systems
It produces a more efficient coding system than ASCI
Encoding where each 16-bit or 32-bit value always represents the same character (it is
worth pointing out here that the ASCII code tables are not standardised and versions other
than the ones shown in tables 1.5 and 1.6 exist).
As can be seen from the table, characters used in languages such as Russian, Greek,
Romanian and Croatian can now be represented in a computer.
Assigment
1. What are the column weightings for the binary number system?
2. Convert these binary numbers into denary.
a) 1110110=54+32+16+4+2=118
b) 00001111
c) 00110011
3. Convert these denary numbers into binary(using either method).
a) 144
b) 200
c) 255
4. Convert these denary numbers into 8-bit binary numbers using two’s complement where
necessary.
a) -116
b) -120
c) 61
5. Carry out these binary additions and subtractions using 8 bit column wieightings. Convert
your answers to denary.
a) 01001011+00100011
b) 00001111+00011100
c) 01111111-01011010
d) 11011111-11000011
6. What are the column weightings for hexadecimal (base 16) number system.
7. Convert these binary numbers into hexadecimal.
a) 0 0 0 1 1 1 1 0 0 0 0 1
b) 1 0 0 0 1 0 0 1 1 1 1 0
c) 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1
d) 0 0 1 1 0 0 1 1 1 1 0 1 0 1 1 1 0
8. Convert these hexadecimal numbers into binary.
a) 5 9
b) A A
c) 4 0 E
d) 9 C C
e) D A 4 7
f) 1 A B 0