Thursday, October 18, 2007

Project-Lesson #3 Number bases revisited

I reviewed my binary explanation and wanted to push a few more points I may not have been clear with.

Say we have the number (in base10) 9876
You can do the math in this fashion
(9 x 10^3) + (8 x 10^2) + (7 x 10^1) + (6 x 10^0)
(9 x 1000) + (8 x 100) + (7 x 10) + (6 x 1)
because
10^3=one thousand 10^2=one hundred 10^1=one ten 10^0=one one

so
9000 + 800 + 70 + 60 = 9876

In English we say nine thousand eight hundred seventy six
With each value (except the ones place) we have a specific way of identifying the power of ten
If you think of numbers in these terms it's easy to understand how each base is related


In binary (base2) say we have the number 1101 (equates to 13 in base10)
(1 x 2^3) + (1 x 2^2) + (0 x 2^1) + (1 x 2^0)
(1 x 8) + (1 x 4) + (0 x 2) + (1 x 1)
because
2^3=8 2^2=4 2^1=2 2^0=1
8 + 4 + 0 + 1 = 13


In hexadecimal (base16) say we have the number F3 (equates to 243 in base10 and 11110011 in base2)
(F x 16^1) + (3 x 16^0)
(15 x 16) + (3 x 1)
240 + 4 = 243

The nice thing about hexadecimal is that you can take any group of 4 bits (binary) into a single hexadecimal number

For example take 11110011 from above
1111 = 16(base10) = F(base16)
0011 = 3(base10) = 3(base16)

So 11110011(base2/binary) = F3(base16/hexadecimal)

Now the reason we use hexadecimal in the first place is because when you start getting into extremely large binary numbers it's just too insane to look at and manipulate directly.

For example the binary number
111111101101110010111010100110000111011001010100001100100001
equates to the hexadecimal value of
FEDCBA987654321

The other reason is with computers there is very little reason to work with anything smaller than 1 byte (8bits)
because you can really do much with less than 256 values. A single byte can be represented by a single hexadecimal number.


The reason I am trying to explain all this is because when I manipulate my video data I will be doing so on a byte for byte basis and will generally express my changes in hexadecimal notation.

No comments: