Professional Documents
Culture Documents
1.1.1 Number Representation
1.1.1 Number Representation
Understanding Of The Basis Of Different Number Systems And Use The Binary, Denary And
Hexadecimal Number System
Binary 2 2 0, 1
R
Octal 8 8 0,1,2,3,4,5,6,7
Decimal 10 10 0,1,2,3,4,5,6,7,8,9
KU
Hexadecimal 16 16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
A
In base 16 we have sixteen symbols to represent each digit.
Decimal Hexadecimal Binary (4-bit)
0 0 0000
1 1 0001
TH
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
ED
9 9 1001
10 A 1010
11 B 1011
12 C 1100
HM
13 D 1101
14 E 1110
15 F 1111
It is easy to convert from binary to hex and hex is easier to read than a long string of 1s and 0s.
Step 2
Write down the hexadecimal equivalent for each group 7 5
of digits.
R
Easy to convert binary to BCD.
No error due to round off.
KU
Disadvantages
Occupies more memory.
Can be harder to perform arithmetic operations.
BCD Addition
Whenever the sum of any two BCD digits is greater than 1001 2 then 01102 has to be added to the
A
result to skip over the unused codes.
Positive integers are generally stored as simple binary numbers. 1 is 1, 10 is 2, 11 is 3, etc.. Negative
TH
integers are stored as the two's complement of their absolute value, i.e. of the corresponding positive
integer. The two's complement of a positive number is, when using this notation, a negative number.
In order to flip the sign of a number, you always calculate the two's complement of that number: flip
all bits, then add 1. This is independent of whether the original number is positive or negative.
Example: 3 in 8-bit signed binary notation is 00000011. To flip the sign, you first flip all bits (11111100),
then add 1 (11111101). So, -3 is 11111101. To flip the sign again, you first flip all bits (00000010), then
ED
add 1 (00000011), and you can see that this is the same 3.
Nearly all computers work purely in binary. That means that they only use ones and zeros, and there's
no - or + symbol that the computer can use. The computer must represent negative numbers in a
different way.
HM
We can represent a negative number in binary by making the most significant bit (MSB) a sign bit,
which will tell us whether the number is positive or negative. The column headings for an 8 bit number
will look like this:
-128 64 32 16 8 4 2 1
MSB LSB
1 0 1 1 1 1 0 1
A
Here, the most significant bit is negative, and the other bits are positive. You start with -128, and add
the other bits as normal. The example above is -67 in denary because: (-128 + 32 + 16 + 8 + 4 + 1 = -
67)
-1 in binary is 11111111.
Note that you only use the most significant bit as a sign bit if the number is specified as signed. If the
number is unsigned, then the msb is positive regardless of whether it is a one or not.
If the MSB is 0 then the number is positive, if 1 then the number is negative.
R
Method: Converting a Negative Denary Number into Binary Twos Complement
KU
Let's say you want to convert -35 into Binary Twos Complement. First, find the binary
equivalent of 35 (the positive version)
32 16 8 4 2 1
A
1 0 0 0 1 1
Now add an extra bit before the MSB, make it a zero, which gives you:
TH
64 32 16 8 4 2 1
0 1 0 0 0 1 1
64 32 16 8 4 2 1
ED
1 0 1 1 1 0 0
64 32 16 8 4 2 1
1 0 1 1 1 0 0
+ 1
1 0 1 1 1 0 1
R
To find the value of the negative number we must find and keep the right most 1 and all
bits to its right, and then flip everything to its left. Here is an example:
KU
1111 1011 note the number is negative
1111 1011 find the right most one
1111 1011
0000 0101 flip all the bits to its left
A
We can now work out the value of this new number which is:
128 64 32 16 8 4 2 1
TH
0 0 0 0 0 1 0 1
4 + 1 = −5 (remember the sign you worked out
earlier!)
ED
To find the value of the negative number we must take the MSB and apply a negative value
to it. Then we can add all the heading values together
HM
So we know how to work out the value of a negative number that has been given to us. How do we
go about working out the negative version of a positive number? Like this, that's how...
R
0000 0101 (5)
KU
0000 0101 find the right most one
0000 0101
1111 1011 flip all the bits to its left
A
So now we can see the difference between a positive and a negative number
Take the binary version of the positive number starting with -128, we know the MSB
is worth -128. We need to work back from this:
ED
-128 64 32 16 8 4 2 1
1 1 1 1 1 0 1 0
-128 +64 +32 +16 +8 +1 = -5
0000 0101 (5)
HM
R
e. 81 (hexadecimal)
f. A8 (hexadecimal)
KU
Convert the following numbers into negative numbers written in binary
g. 000 0001
h. 0110 0000
i. 0111 1111
j. 12 (denary)
A
k. 67 (denary)
l. 34
m. 34 (hexadecimal)
n. 7E (hexadecimal)
TH
ED
HM
A
Binary Subtraction
When it comes to subtracting one number from another in binary things can get very messy.
R
Y (78 denary) 0100 1110 −
KU
An easier way to subtract Y from X is to add the negative value of Y to the value of X
X−Y = X+(−Y)
A
0100 1110 find the right most one TH
0100 1110
1011 0010 flip all the bits to its left
128 64 32 16 8 4 2 1
0 0 0 0 0 1 0 0
4 = 4 = 82-78
A
Find the answers to the following sums in binary, show your working
R
0001 1111 (31)
KU
- 0001 0011 (19)
A
23 (hex)
- 1F (hex)
TH
0001 0010 (10)
- 1110 0001 (-31)
Further Notes
http://academic.evergreen.edu/projects/biophysics/technotes/program/2s_comp.htm#calculate
ED
Understanding of, and be able to represent, character data in its internal binary form depending
on the character set used (Candidates will not be expected to memorise any particular
character codes but must be familiar with ASCII and Unicode.)
Char Ctrl Dec Hex Char Dec Hex Char Dec Hex Char Dec Hex
<space
NUL ^@ 0 00 > 32 20 @ 64 40 ` 96 60
SOH ^A 1 01 ! 33 21 A 65 41 a 97 61
STX ^B 2 02 " 34 22 B 66 42 b 98 62
A
ETX ^C 3 03 # 35 23 C 67 43 c 99 63
EOT ^D 4 04 $ 36 24 D 68 44 d 100 64
ENQ ^E 5 05 % 37 25 E 69 45 e 101 65
BS ^H 8 08 ( 40 28 H 72 48 h 104 68
HT ^I 9 09 ) 41 29 I 73 49 i 105 69
LF ^J 10 0A * 42 2A J 74 4A j 106 6A
VT ^K 11 0B + 43 2B K 75 4B k 107 6B
R
FF ^L 12 0C , 44 2C L 76 4C l 108 6C
KU
CR ^M 13 0D - 45 2D M 77 4D m 109 6D
SO ^N 14 0E . 46 2E N 78 4E n 110 6E
SI ^O 15 0F / 47 2F O 79 4F o 111 6F
DLE ^P 16 10 0 48 30 P 80 50 p 112 70
A
DC1 ^Q 17 11 1 49 31 Q 81 51 q 113 71
DC2 ^R 18 12 2 50 32 R 82 52 r 114 72
DC3 ^S 19 13 3
TH
51 33 S 83 53 s 115 73
DC4 ^T 20 14 4 52 34 T 84 54 t 116 74
NAK ^U 21 15 5 53 35 U 85 55 u 117 75
SYN ^V 22 16 6 54 36 V 86 56 v 118 76
ETB ^W 23 17 7 55 37 W 87 57 w 119 77
ED
CAN ^X 24 18 8 56 38 X 88 58 x 120 78
EM ^Y 25 19 9 57 39 Y 89 59 y 121 79
SUB ^Z 26 1A : 58 3A Z 90 5A z 122 7A
HM
ESC ^[ 27 1B ; 59 3B [ 91 5B { 123 7B
FS ^\ 28 1C < 60 3C \ 92 5C | 124 7C
GS ^] 29 1D = 61 3D ] 93 5D } 125 7D
RS ^^ 30 1E > 62 3E ^ 94 5E ~ 126 7E
<del
A
e
US ^_ 31 1F ? 63 3F _ 95 5F t 127 7F
e
>
ASCII (American Standard Code for Information Interchange)is a 7-bit character code that was
introduced by American National Standards Institute (ANSI) and is used by most U.S. personal and
workstation computers.
Acronym for American Standard Code for Information Interchange. A coding scheme using 7 or 8
bits that assigns numeric values to up to 256 characters, including letters, numerals, punctuation
R
marks, control characters, and other symbols. ASCII was developed in 1968 to standardize data
transmission among disparate hardware and software systems and is built into most minicomputers
and all PCs. ASCII is divided into two sets: 128 characters (standard ASCII) and an additional 128
KU
(extended ASCII).
EBCDIC (Extended Binary Coded Decimal Interchange Code) was developed by IBM for use on their
mainframe computers.
Unicode is a character coding system designed to support the worldwide interchange and display
A
of written texts of diverse languages by providing a unique number for every character.
A 16-bit character encoding standard developed by the Unicode Consortium between 1988 and
1991. By using two bytes to represent each character, Unicode enables almost all of the written
languages of the world to be represented using a single character set. (By contrast, 8-bit ASCII is not
TH
capable of representing all of the combinations of letters and diacritical marks that are used just
with the Roman alphabet.) Approximately 39,000 of the 65,536 possible Unicode character codes
have been assigned to date, 21,000 of them being used for Chinese ideographs. The remaining
combinations are open for expansion.
Express a denary number in Binary Coded Decimal (BCD) and vice versa
1. 45
4 5
0100 0101
= 01000101
2. 98 ?
HM
9 8
1001 1000
= 10011000
2. 01100011
0110 0011
6 3
=63
http://www.miniwebtool.com/bcd-to-decimal-converter/
http://www.miniwebtool.com/decimal-to-bcd-converter/
Binary-coded Decimal or BCD is a way of representing a decimal number as a string of bits suitable
for use in electronic systems. Rather than converting the whole number into binary, BCD splits the
number up into its digits and converts each digit to 4-bit binary.
R
0011 0100 0101
This is 3 digits longer than the real binary equivalent of 345, 101011001, but it has several advantages
and disadvantages.
KU
Advantages
It can easily be used to drive displays, as each digit is encoded separately.
It allows each conversion to decimal; true binary to decimal conversion is difficult and gets
increasingly difficult as the number gets longer.
It allows easy scaling by factors of 10
A
Disadvantages:
It is difficult to perform arithmetic operations (such as adding) on BCD numbers, as it is not as
easy to recognise carries, etc.
It is longer than true binary, and so require more storage space.
TH
ED
HM
A