50: Hexadecimal. Easier Than Binary.
Take Up Code - A podcast by Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes
Categories:
Hexadecimal gives you a better way to represent binary numbers. In one of the very early episodes, I explained how bytes are composed of eight bits. On some platforms, a byte might actually be more than eight bits. The real problem though is even eight bits are hard to read. The zeros and ones blend together. Hexadecimal allows you to work with four bits at a time and is much easier to read. Here’s table of some common values: Decimal Binary Hexadecimal 0 00000000 0x00 1 00000001 0x01 2 00000010 0x02 3 00000011 0x03 4 00000100 0x04 5 00000101 0x05 6 00000110 0x06 7 00000111 0x07 8 00001000 0x08 9 00001001 0x09 10 00001010 0x0a 11 00001011 0x0b 12 00001100 0x0c 13 00001101 0x0d 14 00001110 0x0e 15 00001111 0x0f 16 00010000 0x10 32 00100000 0x20 64 01000000 0x40 128 10000000 0x80 255 11111111 0xff Listen to the full episode for more or you can also read the full transcript below. Transcript It doesn’t matter what number system you’re working with, well, except maybe Roman numerals which are just too difficult to add and subtract. The problem with Roman numerals is that there’s no placeholder system. So let me first clarify that it doesn’t matter what placeholder number system you’re working with. There is one rule that applies to them all. You need unique symbols that represent each digit starting with zero. However many digits you have will be based on the placeholder value system you’re using. This is called the number system base. For our everyday counting, we use a base ten number system. However, our school system has failed us. It’s not really the fault of the school system really. This failure goes back much farther than any modern school system. You see, we were all taught to count wrong. When counting on our fingers, we naturally start with one and go to ten. We have a base ten number system and we have ten fingers so it makes sense that when we hold up a single finger, that’s one and when we hold up all ten fingers, that’s ten. This simple mistake in the way we count is probably the single biggest obstacle that prevents a lot of people from understanding different number systems. Here’s what I’d like you to do. It’s also a very simple and small change. When you count, start from zero. Get in the habit of recognizing zero as a valid digit all by itself. Most people associate zero more with the value ten than with zero itself. As you develop this way of thinking, you’ll find it comes easier and will prepare you for how most collections treat the first item in the collection to be at index zero. It will also help you understand placeholder number systems. Because no matter what number system you use, they all start with zero. Our base ten number system has ten digits. These digits are zero through nine. They are most definitely not one through ten. Forget what you learned in Sesame Street and first grade. and remember that numbers start at zero. Why is this so important that I’d spend the whole first half of this episode trying to convince you to start counting at zero? I’ll explain that right after this message from our sponsor. ( Message from Sponsor ) Going back to an eight bit byte, there are 256 possible values that range from 0 through 255. See, there’s that whole start from zero thing again. If we wanted to, we could assign a unique symbol for each of these values. That’s quite a daunting task. Could you easily memorize 256 squiggly shapes and how would we draw them anyway so they would be easily recognizable? We don’t even have a very good way of distinguishing the 26 letters in the English language. I mean really, just look at the difference between a capital O and a capital Q. It’s just one tiny tail of a mark that separates them. Imagine if we tried to come