Question about conversion hex to binary

42 views
Skip to first unread message

Boina Roja

unread,
Apr 25, 2013, 8:42:04 AM4/25/13
to codes...@googlegroups.com
I am going through the numbers as bits vid and it says at 26:08 that each hex digit corresponds to 4 binary digits. Why does that differ from octal, where each digit corresponds with 3 binary digits?

Russel Walker

unread,
Jun 23, 2013, 11:02:24 AM6/23/13
to codes...@googlegroups.com


On Thursday, April 25, 2013 2:42:04 PM UTC+2, Boina Roja wrote:
I am going through the numbers as bits vid and it says at 26:08 that each hex digit corresponds to 4 binary digits. Why does that differ from octal, where each digit corresponds with 3 binary digits?


The reason why each octal digit corresponds with 3 binary digits is because binary is base 2 and octal is base 8 and 8 is a power of 2. i.e. 2^3 = 8.

Similarly with hex which is base 16, 2^4 = 16.

The number system isn't designed in a way that each digit corresponds with some number of digits of another number system. It just so happens mathematically that if a numeral systems base is a power or another numerals systems base, then conversion between these two numerals systems follows very easily with some number of digits of the numeral system with a smaller base corresponds with 1 digit of the numeral systems with the bigger base.

Lets say I'm using a numeral system which is base 64. Because 64 is a power of 2 (2^6 = 64) then I can safely assume that 1 digit in base 64 will correspond to 6 binary digits. Also, because 64 is a power of 8 (8^2 = 64) I can assume 1 digit in base 64 will correspond with 2 octal digits.

And lastly, the reason why we use hex and octal in computing is precisely because 8 and 16 are powers of two so conversion between hex and binary, and conversion between octal and binary, is much easier and one can even learn to do the conversions mentally.

The history of this goes back, as far as I know, to programming in machine code which are instructions that are represented with binary digits instead of characters and words like in most programming languages today. But because binary is very hard for human beings to process mentally, they program machine code in hex instead which is much more dense and easier on your brain, where the hex code is just another representation of the binary code which corresponds directly.

Hope that made sense.

Brian Will

unread,
Jun 25, 2013, 8:03:17 AM6/25/13
to codes...@googlegroups.com
Thanks, Russel, that's a good explanation. It's really just a quirk of position notation numbering systems. We take advantage of it in programming simply to express binary data more compactly but still in a form where a human can easily 'see' the individual bits (with a little practice).

I'd only add that this quirk of positional notation works for other number bases. E.g. because 9 is 3^2, one digit of a base-9 number corresponds to two digits of a base-3 number, and because 27 is 3^3, one digit of a base-27 number corresponds to three digits of a base-3 number. More generally, for any base-n, one digit of a base-(n^m) number corresponds to m digits of a base-n number. So this quirk isn't special to binary, but binary data is what we care about in programming.


--
You received this message because you are subscribed to the Google Groups "codeschool" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codeschool+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Russel Walker

unread,
Jun 27, 2013, 10:57:39 AM6/27/13
to codes...@googlegroups.com
I saw the name codeschool and had assumed it was the .com site which I only poked around for a bit (didn't quite take to it). It's just funny cos all the information in my answer I picked up off of your videos. But only when I saw the name Brian Will in your reply did it click.

I always recommend your youtube channel and site as a the best resource to learn programming from the fundamentals throughout. Although I haven't finished watching all the videos due to time constraints. I just want to say thanks!!! And your actually one of my heros. Not to get all awkard or anything haha.

Cheers
Reply all
Reply to author
Forward
0 new messages