Академический Документы
Профессиональный Документы
Культура Документы
1 Information representation
Binary
Denary
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
10
1011
11
1100
12
1101
13
1110
14
1111
15
Denary/Decimal
Page 1 of 19
10^2
1000
5
100
9
10^1 10^0
10
7
1
3
Using the above table we can see that each column has a different value assigned to it. And if we know the
column values we can know the number, this will be very useful when we start looking at other base systems.
Obviously, the number above is: five-thousands, nine-hundreds, seven-tens and three-units.
5*1000 + 9*100 + 7*10 + 3*1 = (5973)10
Page 2 of 19
64
1
32
1
16
0
8
1
4
0
2
1
1
0
Using the above table we can see that each column has a value assigned to it that is the power of two (the base
number!), and if we take those values and the corresponding digits we can work out the value of the number:
1*64 + 1*32 + 1*8 + 1*2 = 106.
If you are asked to work out the value of a binary number, the best place to start is by labeling each column
with its corresponding value and adding together all the columns that hold a 1. Let's take a look at another
example:
(00011111)2
128
64
32
16
8
4
2
1
0
0
0
1
1
1
1
1
So now all we need to do is to add the columns containing 1s together:
1*16 + 1*8 + 1*4 + 1*2 + 1*1 = 31
Exercise: Binary
32
0
16
0
8
1
4
1
2
0
1
0
16
1
8
1
4
0
2
0
1
1
Answer :
128
64
0
0
4 + 2 + 1 = (7)10
32
0
16
0
8
0
4
1
2
1
1
1
16
1
8
0
4
1
2
0
1
1
Is there a short cut to working out a binary number that is made of solid ones, such as:
(01111111)2?
Answer :
Yes, take the first 0's column value and minus one
128
64
32
16
8
4
0
1
1
1
1
1
= 128 - 1 = 127 = 64 + 32 + 16 + 8 + 4 + 2 + 1
2
1
1
1
Page 4 of 19
What is a byte?
In the world of computers and microcontrollers, 8 bits are considered to be a standard group. It is called
a byte. Microcontrollers are normally byte oriented and data and instructions normally use bytes. A Byte can
be broken down into two nibbles.
Byte
1
What is a word?
Going bigger, a group of bytes is known as a word. A word normally consists of two and sometimes more
bytes belonging together.
Word
1
Hexadecimal
You may notice from the table that one hexadecimal digit can represent exactly 4 binary bits. Hexadecimal is
useful to us as a shorthand way of writing binary, and makes it easier to work with long binary numbers.
Hexadecimal is a base-16 number system which means we will have 16 different numbers to represent our
digits. The only problem being that we run out of numbers after 9, and knowing that 10 is counted as two
digits we need to use letters instead:
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
We can do exactly the same thing as we did for denary and binary, and write out our table.
Page 5 of 19
16^4
65536
0
16^3
4096
3
16^2
256
4
16^1
16
A
16^0
1
F
So now all we need to do is to add the columns containing values together, but remember that A = 10, B = 11,
C = 12, D = 13, E = 14, F = 15.
3*4096 + 4*256 + (A)10*16 + (F)15*1 = (13487)16
You might be wondering why we would want to use hexadecimal when we have binary and denary, and when
computer store and calculate everything in binary. The answer is that it is entirely for human ease. Consider
the
following example:
Error messages are written using hex to make it easier for us to remember and record them
Page 6 of 19
Base
base-16 hexadecimal
15728145
base-10 denary
Page 7 of 19
Exercise: Hexadecimal
16
A
1
1
16 * 10 + 1 * 1 = (161)10
16
F
1
F
16 * 15 + 1 * 15 = (255)10
1
D
16 * 0 + 1 * 13 = (13)10
Page 8 of 19
1
7
16 * 3 + 1 * 7 = (55)10
Page 9 of 19
0110
(2+4=6)
1100
(4+8=12)
1111
(1+2+4+8=15)
0101
(1+4=5)
So the binary number 0110110011110101 is 6CF5 in hexadecimal. We can check this by converting both to
denary. First we'll convert the binary number, since you already know how to do this:
32768
16384
8192
4096
2048
1024
512
256
128
64
32
16
4096
6
256
C
16
F
1
5
Page 10 of 19
Totaling them all up gives us 27893, showing that 0110110011110101 is equal to 6CF5.
To convert from denary to hexadecimal, it is recommended to just convert the number to binary first, and then
use the simple method above to convert from binary to hexadecimal.
In summary, to convert from one number to another we can use the following rule:
Hexadecimal Binary Denary
Page 11 of 19
2
0010
128
64
0
0
2+16 = 18 (decimal)
(Hex)
(Binary)
32
0
16
1
8
0
4
0
2
1
1
0
4
1
2
0
1
1
4
1
2
1
1
1
5
0101
128
64
1
0
128+32+4+1 = 165 (decimal)
(Hex)
(Binary)
32
1
16
0
8
0
(Hex)
(Binary)
16
1
8
1
Page 12 of 19
0
0000
64
0
(Hex)
(Binary)
32
0
16
1
8
0
4
0
2
0
1
0
1101
D
(Binary)
(Hex)
(Binary)
(Hex)
Answer :
1010
A
1111
F
(Binary)
(Hex)
Page 13 of 19
Answer :
1110
1010
E
A
Hence, (111010100001)2 >> (EA1)16
0001
1
(Binary)
(Hex)
0101
5
0111
7
16
1
8
0
4
1
2
1
1
1
8
1
4
1
2
0
1
0
(Binary)
(Hex)
0000
0
1100
C
16
0
(Binary)
(Hex)
64
1
32
1
16
1
8
0
4
1
2
0
01110101=64+32+16+4+1 = 117(decimal)
0111
7
0101
5
(Binary)
(Hex)
Page 15 of 19
1
1
64
32
16
MSB
LSB
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. (-128 + 127)
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.
Twos Complement:
The MSB stays as a number, but is made negative. This means that the column headings are
-128
64
32
16
Twos complement seems to make everything more complicated for little reason at the moment, but later it
becomes essential for making the arithmetic easier.
The Standard ASCII Character Set
Page 16 of 19
<spc>
<spc>
70
111
117
114
32
97
110
100
32
115
101
118
101
110
By looking in the ASCII table, you can see a one-to-one correspondence between each character and the
ASCII code used. Note the use of 32 for a space -- 32 is the ASCII code for a space. We could expand these
decimal numbers out to binary numbers (so 32 = 00100000) if we wanted to be technically correct -- that is
how the computer really deals with things.
The first 32 values (0 through 31) are codes for things like carriage return and line feed. The space character is
the 33rd value, followed by punctuation, digits, uppercase characters and lowercase characters. To see all 127
values try Google ASCII codes.
Page 17 of 19
Page 18 of 19
3 = 0011
9 = 1001
8 = 1000
6 = 0110
0 = 0000
2 = 0010
Page 19 of 19