OnErr0r
12-31-2002, 11:42 PM
Bits, Bytes and Bases
Bases:
Everyone knows how to count to ten, and whether you knew or considered it,
that system with ten digits is called base 10 or decimal. A decimal system
consists of ten digits 0 to 9, which can represent any number.
You were probably exposed to the Base 2 system in elementary school,
and promptly forgot about it (if you were like me). "What good is that?",
I thought at the time. But it is VERY important in computing. Base 2 has
only two digits 0 and 1, which correspond to off and on.
Think of it like a light switch.
0 = Off
1 = On
Counting is very simple, we count in the same way as base 10, when we run
out of digits, we increment the next place and continue.
Binary Decimal
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
Now consider another equally important Base in computing, Base 16 or
Hexadecimal, Hex for short. Since it uses more than our "normal" ten decimal
digits, symbols are used to represent some of the digits. Namely A to F. We
count as follows:
Decimal HEXadecimal
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9 (All fine to here)
10 A (Start using symbols for digits)
11 B
12 C
13 D
14 E
15 F
Ok, what's next? Just like with Decimal once we've run out of digits,
we start again with the next number. And its 10, but this one-zero doesn't mean
the same thing as usual. Oh yeah, VB uses &H to denote Hex numbers.
(Remember that any number raised to the zero power is 1. And any number raised
to a power of one is the number itself.)
__________________________________________
&H10 = 1 * (16 ^ 1) + 0 * (16 ^ 0)
&H10 = (1 * 16) + (0 * 1)
&H10 = 16 + 0 = 16 (decimal)
__________________________________________
&HFF = 15 * (16 ^ 1) + 15 * (16 ^ 0)
&HFF = (15 * 16) + (15 * 1)
&HFF = 240 + 15 = 255 (decimal)
__________________________________________
If all the above was not clear, you might want to reread it.
__________________________________________
Bits and Bytes:
Bits are just base two digits, they are either on or off.
0 = Off
1 = On
Four bits together are called a nibble. Eight bits makes a byte.
Binary Hex
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = A
1011 = B
1100 = C
1101 = D
1110 = E
1111 = F
Notice that one nibble (four bits) is also one Hex digit. This is a
very important relationship. And two nibbles makes one byte.
A 0
&HA0 = 1010 0000
F F
&HFF = 1111 1111
So! We see that its very easy to represent any Hex number by breaking
it down into nibbles. What about a 16 bit integer?
8 0 A 1
&H80A1 = 1000 0000 1010 0001
Study this relationship carefully, it will be invaluable to any programmer.
Lets review, a bit is a binary digit and is either on or off. Four bits
makes a nibble. Each nibble is one Hex digit. Eight bits or two nibbles makes
a byte.
Bases:
Everyone knows how to count to ten, and whether you knew or considered it,
that system with ten digits is called base 10 or decimal. A decimal system
consists of ten digits 0 to 9, which can represent any number.
You were probably exposed to the Base 2 system in elementary school,
and promptly forgot about it (if you were like me). "What good is that?",
I thought at the time. But it is VERY important in computing. Base 2 has
only two digits 0 and 1, which correspond to off and on.
Think of it like a light switch.
0 = Off
1 = On
Counting is very simple, we count in the same way as base 10, when we run
out of digits, we increment the next place and continue.
Binary Decimal
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
Now consider another equally important Base in computing, Base 16 or
Hexadecimal, Hex for short. Since it uses more than our "normal" ten decimal
digits, symbols are used to represent some of the digits. Namely A to F. We
count as follows:
Decimal HEXadecimal
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9 (All fine to here)
10 A (Start using symbols for digits)
11 B
12 C
13 D
14 E
15 F
Ok, what's next? Just like with Decimal once we've run out of digits,
we start again with the next number. And its 10, but this one-zero doesn't mean
the same thing as usual. Oh yeah, VB uses &H to denote Hex numbers.
(Remember that any number raised to the zero power is 1. And any number raised
to a power of one is the number itself.)
__________________________________________
&H10 = 1 * (16 ^ 1) + 0 * (16 ^ 0)
&H10 = (1 * 16) + (0 * 1)
&H10 = 16 + 0 = 16 (decimal)
__________________________________________
&HFF = 15 * (16 ^ 1) + 15 * (16 ^ 0)
&HFF = (15 * 16) + (15 * 1)
&HFF = 240 + 15 = 255 (decimal)
__________________________________________
If all the above was not clear, you might want to reread it.
__________________________________________
Bits and Bytes:
Bits are just base two digits, they are either on or off.
0 = Off
1 = On
Four bits together are called a nibble. Eight bits makes a byte.
Binary Hex
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = A
1011 = B
1100 = C
1101 = D
1110 = E
1111 = F
Notice that one nibble (four bits) is also one Hex digit. This is a
very important relationship. And two nibbles makes one byte.
A 0
&HA0 = 1010 0000
F F
&HFF = 1111 1111
So! We see that its very easy to represent any Hex number by breaking
it down into nibbles. What about a 16 bit integer?
8 0 A 1
&H80A1 = 1000 0000 1010 0001
Study this relationship carefully, it will be invaluable to any programmer.
Lets review, a bit is a binary digit and is either on or off. Four bits
makes a nibble. Each nibble is one Hex digit. Eight bits or two nibbles makes
a byte.