Navi Menu
main blog files profquotes Zygote Asylum contact link junk

19day

2007-05-01

An exercise in Hex

Filed under: General — 19day @ 21:03:27

Humans deal in Base 10, with the numbers 0, 1, 2, 4, 5, 6, 7, 8, 9, but Computers deal in binary numbers, 1 and 0, also called Base 2

Base 2 numbers are very long, and hard to look at, take a look at this number I picked at random
00001001111110010001000100000010100111010111010011100011010110111101100001000001010101101100010101100011010101101000100011000000

wow, that’s pretty long and hard to look at… it happens to be 13,256,278,887,989,457,651,018,865,901,401,704,640 in Base 10 notation.
How do you do that? Well, each digit is an additional power of 2, just like in a base 10 number each digit is a power of 10, the right most (or least significant digit) is 10 to the power of 0, multiplied with the digit, making it the digit itself, the next number is 10 to the power of 1 multiplied by the digit, and add them all up. In Base 2, it’s 2 to the power of the digit.

But Computers deal in Binary, but it’s hard to look at them, so we break them up into groups of 4:
0000
1001
1111
1001
0001
0001
0000
0010
1001
1101
0111
0100
1110
0011
0101
1011
1101
1000
0100
0001
0101
0110
1100
0101
0110
0011
0101
0110
1000
1000
1100
0000

Each set of 4 bits can represent 16 numbers,
0000 = 0
0001 = 1
0010 = 2
0011 = 3

1111 = 15

Base 16, known as Hexidecimal, is nicely compatible with binary since you can do this chunking and translate the digits directly.
So in base 16, the numbers 0 through 15 have a single “symbol” to represent them, like 9 is 9, but A is 10, B 11, C 12, D 13, E 14 and F 15

So take our chunks and work out what number it is in Hex

0000 = 0
1001 = 9
1111 = F
1001 = 9
0001 = 1
0001 = 1
0000 = 0
0010 = 2
1001 = 9
1101 = D
0111 = 7
0100 = 4
1110 = E
0011 = 3
0101 = 5
1011 = B
1101 = D
1000 = 8
0100 = 4
0001 = 1
0101 = 5
0110 = 6
1100 = C
0101 = 5
0110 = 6
0011 = 3
0101 = 5
0110 = 6
1000 = 8
1000 = 8
1100 = C
0000 = 0

And when you arrange the string of Hex digits back into a row, you can see, it’s easier to read

And so concludes converting a totally random series of bits into Hex.

I’ll write about Montreal later.

1 Comment »

  1. Should be useful for CS241…

    Comment by Curtis — 2007-05-02 @ 14:00:40

RSS feed for comments on this post.

Leave a comment

You must be logged in to post a comment.

Powered by WordPress


Page by 19day (S.B.H.)
Everything here is property of 19day productions, unless it isn't, and cannot be claimed by anyone else regardless, sort of like a copyright, but in many more words.
Last modified: September 07 2009 18:21:00.
Valid XHTML 1.0! Valid CSS! CWH Get Firefox