Professional Documents
Culture Documents
Binary
Denary
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
10
1011
11
1100
12
1101
13
1110
14
1111
15
Page 1 of 17
10^2
100
10^1 10^0
10
1
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
R
2^6
64
1
2^5
32
1
2^4
16
0
2^3
8
1
2^2
4
0
2^1
2
1
2^0
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
R
Page 2 of 17
Answer :
128
64
0
0
8+4 = (12) 10
32
0
16
0
8
1
4
1
2
0
1
0
Answer :
128
64
32
0
1
0
64 + 16 + 8 + 1 = (89) 10
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
Answer :
128
64
32
0
1
0
64 + 16 + 4 + 1 = (85) 10
16
1
8
0
4
1
2
0
1
1
Answer :
Yes, take the first 0's column value and minus one
128
64
32
16
8
4
2
0
1
1
1
1
1
1
= 128 - 1 = 127 = 64 + 32 + 16 + 8 + 4 + 2 + 1
1
1
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
Page 4 of 17
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
R
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:
Page 5 of 17
Base
EFFE11
base-16 hexadecimal
15728145
base-10 denary
111011111111111000010001 base-2 binary
All the numbers are the same and the easiest version to remember/understand for humans is the base16. Hexadecimal is used in computers for representing numbers for human consumption, having uses for
things such as memory addresses and error codes. NOTE: Hexadecimal is used as it is shorthand for
binary and easier for people to remember. It DOES NOT take up less space in computer memory, only on
paper or in your head! Computers still have to store everything as binary whatever it appears as on the
screen.
Exercise: Hexadecimal
U
1
1
16 * 10 + 1 * 1 = (161) 10
R
1
F
16 * 15 + 1 * 15 = (255) 10
R
Page 6 of 17
1
D
16 * 0 + 1 * 13 = (13) 10
R
1
7
16 * 3 + 1 * 7 = (55) 10
R
Page 7 of 17
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:
3276
8
1638
4
819
2
409
6
204
8
102
4
51
2
25
6
12
8
6
4
3
2
1
6
256
C
16
F
1
5
Page 8 of 17
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 9 of 17
Answer :
1
0001
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
Answer :
A
1010
5
0101
128
64
32
1
0
1
128+32+4+1 = 165 (decimal)
(Hex)
(Binary)
16
0
8
0
Answer :
7
F
0111
1111
128
64
32
0
1
1
64+32+8+4+2+1 = 127 (decimal)
(Hex)
(Binary)
16
1
8
1
Page 10 of 17
Answer :
1
0001
0
0000
128
0
16(decimal)
64
0
(Hex)
(Binary)
32
0
16
1
8
0
4
0
2
0
1
0
Answer :
1010
A
1101
D
(Binary)
(Hex)
Answer :
0011
0111
3
7
Hence, (110111) 2 >> (37) 16
R
(Binary)
(Hex)
Answer :
1010
A
1111
F
(Binary)
(Hex)
Page 11 of 17
Answer :
1110
1010
E
A
Hence, (111010100001) 2 >> (EA1) 16
R
0001
1
(Binary)
(Hex)
Answer :
128
64
32
16
0
1
0
1
0101 0111= 64+16+4+2+1 = 87(decimal)
0101
5
0111
7
8
0
4
1
2
1
1
1
4
1
2
0
1
0
(Binary)
(Hex)
Answer :
128
64
32
0
0
0
00001100 = 8+4 = 12(decimal)
0000
0
1100
C
16
0
8
1
(Binary)
(Hex)
Page 12 of 17
Answer :
128
0
64
1
32
1
16
1
8
0
4
1
2
0
1
1
01110101=64+32+16+4+1 = 117(decimal)
0111
7
0101
5
(Binary)
(Hex)
Page 13 of 17
64
32
16
MSB
1
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.
Page 14 of 17
<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 15 of 17
Page 16 of 17
3 = 0011
9 = 1001
8 = 1000
6 = 0110
0 = 0000
2 = 0010
Page 17 of 17