What wasn’t mentioned in the video is that hexadecimal has a very straight relation to binary (and vice-versa) and thus it became the major thing to represent numbers for computer people.

You need to grasp the idea of half a byte which is called a nibble (or nybble). One byte consists of 8 bits (where one bit is either 0 or 1) so a half-byte or nibble is 4 bits. Simple, eh?

If you take a look at what can be represented with 4 bits you will see it ranges from

0000 to 1111

Ring a bell? 1111, as you should know by now, is 15. Thus a nibble can be immediately represented by one hex digit (0…F = 0…15).

Thus when converting binary to hex just group the digits in blocks of four (which is recommended for readability purposes anyway) and you can immediately deduct the hex number:

0101 1101 1111 0010
v
5 D F 2

You can even pick the order any way you like, just look at the nibbles and convert them individually! This is also why one byte or 8-bit color entry can be represented by two hex digits, one for each of the byte halfes.

Word of warning: Computers are special with respect to negative numbers and I expect this to be covered later in the course - when going to or from decimal crossing the magical boundaries (like -1 or 2^32 for 32-bit integer values) things may not be like you expect them (hint: sign bit, two’s complement).

So for brevity on a simple 8-bit machine like the C64 (8-bit registers - so it can only handle an 8-bit number or byte in one go):

0x80 (or 80h - both ways to express hexadecimal)
-> you might think of it as 129
-> computer may rather think of it as -128

Regards

6 Likes

Thanks for sharing this excellent explanation @pro79. Binary and Hex do indeed make good bedfellows!

THX! for reminding me! It’s long ago, working on that level
I think because, these tiny technical thingies, are all automated away …

Have fun!

2 Likes

Brilliantly explained, great stuff.

Good share, great to refresh memory. I remember the terms but forgotten the concept. Thanks for sharing

1 Like