The binary and
hexidecimal numbering systems have always presented a huge problem for most
students. Actually, if I look through the different computer books and study
material that try to explain the subject, its really no wonder. I have found
information that explains it using boxes, building blocks, candles, cars.... I
have no idea what this is myself. In fact, just as you start to think you've
got a handle on it, you read another explanation that tends to confuse you
entirely. So, at the risk of baffling you completely, I'll try to explain,
using another method, the method my grade 2 teacher (or maybe grade 3, I can't remember)
taught me to understand decimal numbers of more than 1 digit. This doesn't work
so well for hexidecimal, because the numbers get real large real quick. But we
can check it out.
First thing to
remember... is that you don't need to learn to count. Unless you're attempting
to understand low level programming, learning binary provides you with two
things:
- comprehension of how your computer stores information, with a better understanding of bits, bytes, kilobytes, etc...
- an easy method of converting between decimal and hexidecimal. You don't have to learn to count in hexidecimal either, but I/O addresses and memory addresses are given in hex and sometimes you can resolve device conflicts by being able to tell if addresses overlap.
So, my suggestion is
to find a conversion method that you can understand, bookmark it or keep it in
a file, then forget about it. Look it up again on the rare occasion that you
might need it. (By the way, my favorite conversion method is a calculator).
All that being said,
lets get back to grade 2.
Decimal
(base 10)
The decimal numbering system is the system we all use in our everyday work. It consists of 10 digits (hence the name decimal). The digits, from smallest to largest are:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Now, any number can
be broken down into columns. From right to left, the first column is the 1's
column, then the 10's column, then the 100's, then the 1000's, etc..
Let's look at the number 137:
Thousands
|
Hundreds
|
Tens
|
Ones
|
0
|
1
|
3
|
7
|
0 X 1000 = 0 (0 thousands)
1 X 100 = 100 (1
hundreds)
3 X 10 = 30 (3 tens)
7 X 1 = 7 (7 ones)
0+100 + 30 + 7 = 137
If you don't
understand it this far, go back over it until you do, or get some help.
OK, lets try the
number 77:
Thousands
|
Hundreds
|
Tens
|
Ones
|
0
|
0
|
7
|
7
|
0 X 1000 = 0 (0
thousands)
0 X 100 = 0 (0 hundreds)
7 X 10 = 70 (7 tens)
7 X 1 = 7 (7 ones)
0 X 100 = 0 (0 hundreds)
7 X 10 = 70 (7 tens)
7 X 1 = 7 (7 ones)
0+0+70 + 7 = 77
If you understand
this far, go on to the next page for binary.
Binary
(base 2)
Your computer works using the binary numbering system. This is because a computer can only recognize two states, the presence of an electrical charge or the absence of an electrical charge. In other words, on or off.
The binary numbering
system is ideal for representing these two states because it consists of only
two digits. The digits, from smallest to largest are:
0, 1.
0 represents the
absence of an electrical charge or 'off'.
1 represents the
presence of an electrical charge or 'on'.
(Now you can understand
why the power switch on your computer is labelled as O/1).
Once again, any
number can be broken down into columns. Each column is a placeholder. Using the
binary numbering system, from right to left, the first column is the 1's
column, then the 2's column, then the 4's, then the 8's, then the 16's column,
then the 32's column, etc..
Let's look at the number 137 again:
One
hundred twenty-eights |
Sixty-
fours |
Thirty-
twos |
Sixteens
|
Eights
|
Fours
|
Twos
|
Ones
|
1
|
0
|
0
|
0
|
1
|
0
|
0
|
1
|
1 X 128 = 128 (1 one
hundred twenty-eights)
0 X 64 = 0 (0
sixty-fours)
0 X 32 = 0 (0
thirty-twos)
0 X 16 =0 (0
sixteens)
1 X 8 = 8 (1 eights)
0 X 4 = 0 (0 fours)
0 X 2 = 0 (0 twos)
1 X 1 = 1 (1 ones)
128 + 0 + 0 + 0 + 8 +
0 + 0 + 1 = 137
Thus, the binary number 10001001 is equal to 137 decimal.
A single digit (0 or
1) is called a 'bit' (binary digit).
The table above contains 8 bits. Each column can contain either a 1 or a 0 ( 'cause there is only 2 digits in the binary numbering system). So, as you can see, it takes 8 bits to represent the decimal number 137.
Make sense?
If you don't understand it this far, go back over it until you do, or get some help.
OK, lets try the
number 77:
One
hundred twenty-eights |
Sixty-
fours |
Thirty-
twos |
Sixteens
|
Eights
|
Fours
|
Twos
|
Ones
|
0
|
1
|
0
|
0
|
1
|
1
|
0
|
1
|
0 X 128 = 0 (0 one
hundred twenty-eights)
1 X 64 = 64 (1
sixty-fours)
0 X 32 = 0 (0
thirty-twos)
0 X 16 =0 (0
sixteens)
1 X 8 = 8 (1 eights)
1 X 4 = 4 (1 fours)
0 X 2 = 0 (0 twos)
1 X 1 = 1 (1 ones)
0 + 64 + 0 + 0 + 8 +
4 + 0 + 1 = 77
Thus, the binary number 01001101 is equal to 77 decimal.
Any character that
you type (including spaces), and any character you can see on your screen,
takes 8 bits for your computer to produce. Eight bits associated
together are called a 'byte'. A byte is the real building block of
computer information. This can form a single character. A character can be a
number, letter, or symbol. The amount of information a device can store is measured
in bytes. Because of this, most numbers and sizes reported by the computer are
evenly divisible by 8.
Multiple bytes associated together are often called a 'word'.
8 bits = 1 byte
1024 bytes = 1
kilobyte (Kb)
1024 kilobytes = 1
megabyte (Mb) (1,048,576 characters or bytes)
1024 megabytes = 1
gigabyte (Gb)
These numbers are
often rounded off for ease of calculation.
You might see 1
megabyte represented as a million bytes (1,000,000 characters), or 1000
kilobytes.
If you understand
this far, go on to the next page for hexidecimal.
Hexidecimal
(base 16)
Remember, that eight bits make a byte, and that it takes eight bits to store a single character in the computer. 1024 bytes make a kilobyte and 1024 is divisible by eight. Seems like the magic number for computers is eight. The thing is, even relatively low binary numbers can be long and cumbersome.
The hexidecimal
numbering system consists of sixteen digits. The digits, from smallest to
largest are:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
Once again, any
number can be broken down into columns. Each column is a placeholder. Using the
hexidecimal numbering system, from right to left, the first column is the 1's
column, then the 16's column, then the 256's, then the 4096's, then the 65536's
column, etc.. Because you multiply the number in each previous column by 16,
you can see that the numbers get very large and scary very quickly.
Here's the number
137:
65536
|
4096
|
256
|
16
|
1
|
8
|
9
|
0 X 65536 = 0 (0
sixty-five thousand five hundred thirty-sixes)
0 X 4096 = 0 (0 four
thousand ninety-sixes)
8 X 16 = 128
9 X 1 = 9
0 + 0 + 128 + 9 = 137
Decimal 137 = 89h
(Hexidecimal)
Here's an easier way.
Any group of 4 binary digits can represent up to sixteen values. A single
hexidecimal digit can stand for any one of the 16 values that can be
represented by any 4 bit binary number. In other words, break any binary number
into groups of 4 bits. Use a chart (or if your memory is good you can use that)
to find the proper hex number that represents those four bits. I know, it
sounds a bit confusing, so let's do a couple.
Here's the chart:
Decimal
|
Hex
|
Binary
|
0
|
0
|
0000
|
1
|
1
|
0001
|
2
|
2
|
0010
|
3
|
3
|
0011
|
4
|
4
|
0100
|
5
|
5
|
0101
|
6
|
6
|
0110
|
7
|
7
|
0111
|
8
|
8
|
1000
|
9
|
9
|
1001
|
10
|
A
|
1010
|
11
|
B
|
1011
|
12
|
C
|
1100
|
13
|
D
|
1101
|
14
|
E
|
1110
|
15
|
F
|
1111
|
Lets try the number
137 again:
From the previous
page, we know that the binary
equivalent is
10001001.
Break this into 2
groups of 4 bits, [1000][1001]
Use the chart to find
Hex numbers
[1000] = 8h
[1001] = 9h
Decimal = 137
Binary equivalent =
10001001
Hexidecimal
equivalent = 89h
Make sense?
If you don't understand it this far, go back over it until you do, or get some help.
Hexidecimal numbers
are followed by a lowercase 'h' to designate them as hex.
One thing to keep in
mind is that if you have a binary number like
10 (2 decimal), you can add zeros to the left to make it a full 4 bit number. eg. 0010
10 (2 decimal), you can add zeros to the left to make it a full 4 bit number. eg. 0010
Decimal
|
Hex
|
Binary
|
0
|
0
|
0000
|
1
|
1
|
0001
|
2
|
2
|
0010
|
3
|
3
|
0011
|
4
|
4
|
0100
|
5
|
5
|
0101
|
6
|
6
|
0110
|
7
|
7
|
0111
|
8
|
8
|
1000
|
9
|
9
|
1001
|
10
|
A
|
1010
|
11
|
B
|
1011
|
12
|
C
|
1100
|
13
|
D
|
1101
|
14
|
E
|
1110
|
15
|
F
|
1111
|
OK, lets try the
number 77:
We know from the
previous page that the binary equivalent is 01001101.
Let's break that into
two groups of 4 bits.
[0100][1101].
Now let's check the
chart.
[0100] = 4h
[1101] = Dh
Decimal = 77
Binary equivalent =
01001101
Hexidecimal
equivalent = 4Dh
Check it!
65536
|
4096
|
256
|
16
|
1
|
4
|
D
|
0 X 65536 = 0 (0 sixty-five thousand
five hundred thirty-sixes)
0 X 4096 = 0 (0 four thousand
ninety-sixes)
0 X 256 = 0 (0 two hundred fifty-sixes)
4 X 16 = 64 (4 sixteens)
D X 1 = 13 (D ones) (remember we're
using hex, D = 13 decimal)
0 +0 + 0 + 64 + 13 = 77 decimal
Now, if all this has
completely confused you, don't worry. Remember, this isn't your only resource.
Check out your books, the internet, ask someone else. Once you've found a
method that you can understand, keep it in mind (or maybe a safer place). If
you need to convert a number, refer to it, make the conversion, then lock it
away again.
Decimal, Hexidecimal, and Binary Values
Digit Values
Decimal
|
100,000
|
10,000
|
1,000
|
100
|
10
|
1
|
Binary
|
512
|
256
|
128
|
64
|
32
|
16
|
8
|
4
|
2
|
1
|
Hexidecimal
|
65,536
|
4,096
|
256
|
16
|
1
|
You didn't think you
were getting away that easy, did you? You have to do a little practise before
you can lock it away entirely!
The digit values are above and your chart is down below. See if you can fill in the missing values.
The digit values are above and your chart is down below. See if you can fill in the missing values.
Decimal
|
Hex
|
Binary
|
0
|
0
|
0000
|
1
|
1
|
0001
|
2
|
2
|
0010
|
3
|
3
|
0011
|
4
|
4
|
0100
|
5
|
5
|
0101
|
6
|
6
|
0110
|
7
|
7
|
0111
|
8
|
8
|
1000
|
9
|
9
|
1001
|
10
|
A
|
1010
|
11
|
B
|
1011
|
12
|
C
|
1100
|
13
|
D
|
1101
|
14
|
E
|
1110
|
15
|
F
|
1111
|
Decimal
|
Hex
|
Binary
|
163
|
?
|
10100011
|
?
|
2Fh
|
?
|
?
|
30h
|
00110000
|
3840
|
?
|
?
|
?
|
?
|
10000000000
|
?
|
4ACh
|
?
|