Hi there,
I was recently working my way through the 6th version of Stephen G Kochans book and i only got as far as page 63 (mortified) I found the content manageable but when hexadecimals were being brought up I started to freak out and haven't gone back to it since - about a month.
Are hexadecimals and complicated maths a very important part of obj c and other languages in general. Should I plough on regardless of my understanding of Hexadecimals??
Thanks Ciara
Understanding hex isn't particularly important. That hex numbers can be converted to and from decimal numbers isn't important.
Here's why they're used at all:
In programming, you work with a lot of booleans - things which are either true or false, 1 or 0. The actual hardware in a computers, however, the RAM and CPU, namely, only work on numbers which have a larger range than that. The smallest most will work with is a byte, which is the size of 8 binary digits.
You could store one boolean per byte, but that would mean that 7/8ths of the binary digits per byte would go unused. Performance freaks will scream about how unacceptable that is.
So what people do is they merge several boolean variables into a more space efficient variable, a byte (which can store 8 booleans) or an int (depends on the platform, can store 16, 32, or 64 booleans).
Suppose someone has a byte storing 4 true values and 4 false values, something like:
1100 1010
It's much clearer to write in binary, because you can clearly see which of the 8 values are true and false, respectively. In contrast, it would look like this as a decimal number:
202
Completely impossible to tell what's true and false.
Now imagine that they have a 64 bit int that they're writing out:
0000 0001 0010 0011 0100 0101 0110 0111
1000 1001 1010 1011 1100 1101 1110 1111
It's a rather wieldy and difficult to read/write/copy/whatever number. So instead of writing it out in binary, they write it in hex:
0123456789ABCDEF
What makes that better than decimal, you might wonder. Each group of four binary digits corresponds exactly to one hexadecimal digit. So if you only care about a binary digit in a particular place, you can look at the hexadecimal number and convert just the single hex digit from hex to binary to find out what the value is.
But none of it matters, at all. This is all about dealing with compressing large amounts of booleans into small amounts of memory. How many booleans are you working with? Unless you're answering something in the millions, I really don't think it's going to do anything to your performance.