I know binary, but have never really tried to learn Octal or Hex. Does anyone have any good references for them? Or, any suggestions for a book or something that talks about different bases of numbers?
|
|
If you already know binary, you're 99% of the way there. I'd recommend just reading Wikipedia (here and here). Here's why: Octal and hex are best thought of as shorthand for binary. If you can express a number in binary, it is trivial to convert it to hex or octal, and vice-versa, when you consider that the radices of these bases (8 and 16) are powers of 2 (the radix of binary). Here is how to do the conversion: Consider the binary number 101001011100. Since 2^3 is 8, split it into groups of 3 starting from the least significant bit and padding zeros as you go:
Now, convert each group to its "decimal" representation:
So 101001011100 in base 2 is 5134 in base 8. Same for hexadecimal, but split it into groups of 4:
And again convert each group into the corresponding value, remembering that 10 = A, 11 = B, ... 15 = F.
So 101001011100 in base 2 is A5C in base 16. |
|||||||||||||||
|
|
You need to learn the concept of bases (or radix) in general. Think of numbers as a load of digits, the column a digit is in corresponds to its weight, every column you go up is a multiple of the base in which you are in. With decimal, base 10, each column can go from 0 to 9, when we reach ten, we have 1 ten and 0 units, so we write it as 10. In octal it is base 8, the digits go from 0 to 7, when we get up to 8, we write 10 again, 1 eight, and 0 units. Hexadecimal (hex = 6, dec = 10 --- base 16) is the same, digits go from 0 to F (that's 0-9 and a-f to represent 10 to 15 as single digits). When we get up to 16, we write 10, 1 sixteen and 0 units. Fifteen is F, the last digit, 31, (16 + 15) is 1F. This link explains it quite nicely, starting off with the basic concept, running through binary well which is nice and simple and finishing with octal and hexadecimal: http://doit.ort.org/course/inforep/130.htm We can use any base, 2-36 are easy to represent, as we have 26 characters and 10 numerals to represent the digits of the number. Always the same principle. |
|||
|
|
|
I use google calculator from time to time and this has improved my hex/octal knowledge http://www.google.com/search?q=0xFF+to+decimal http://www.google.com/search?q=0o10+to+decimal The key is to have something at hand to translate. |
|||
|
|
|
I'll contribute the following (see chapter 3): This may not be all you need, but it may be helpful. In addition it provides information on related programming topics such as: bitwise operations, signed/unsigned number representation, shift/rotates, etc... Just one warning, this is an assembly language book, so there are a couple of program examples you can safely skip. Everything you want is in volume 1 chapter 3. |
|||
|
|
|
In base 10, from right to left, you have a digit for ones, a digit for tens, a digit for hundreds, a digit for thousands and so on. Each digit leftward has ten times the weight. In base 8, from right to left, you have a digit for ones, a digit for eights, a digit for sixty-fours, a digit for five-hundred-and-twelves and so on. Each digit leftward has eight times the weight. 8 decimal is 10 in octal, 64 decimal is 100 octal, 512 decimal is 1000 octal. In base 16, from right to left, you have a digit for ones, a digit for sixteens, a digit for two-hundred-and-fifty-sixes and so on. Each digit leftward has sixteen times the weight. 16 decimal is 10 in hex, 256 decimal is 100 hex, 4096 decimal is 1000 hex. In base n, each digit leftward has n times the weight. n is 10 in base n. n-squared is 100 in base n. n-cubed is 1000 in base n. If you take p repeats of n and multiply them together (ie n raised to the power p), the result is 1 followed by p zeros in base n. Normally, a base is a whole number, two or greater. However, I've seen some math (fractal related) that works complex numbers as bases. In this case, "digits" can IIRC be any whole number, with no maximum. |
|||
|
|
|
Simply practice, practice, practice. I "know" octal, but never use it, so it takes me some time to do conversions. On the other hand, I use hex frequently and so I've become fluent in it. I can even do quite a bit of hex -> ASCII conversion in my head now. There is no "resource" I used to learn this, it's simply repetition of a task. Any decent calculator app on your computer will be able to do dec/hex/oct/bin conversions while you practice, and I prefer this site or this site (before my workplace blocked it) to get the feel for hex/ascii. |
|||
|
|
