Recently, I came across a #define in my day job that was something like:
#define HEX_255 0xff
It made me think about all the various ways a number can be represented in C. Three of these are standard, but the binary representation is not (unless it’s been added to the standard since I last looked). I’ve found the binary version available in GCC and at least one embedded compiler I use.
// There are exactly the same. unsigned int value1 = 255; // 255 in decimal unsigned int value2 = 0xff; // 255 in hexadecimal unsigned int value3 = 0377; // 255 in octal unsigned int value4 = 0b11111111; // 255 in binary printf ("%u %u %u %u\n", value1, value2, value3, value4);
It made me wonder … what does one use octal for? I remember being excited when I realized an old synthesizer I had was using octal for it’s sound selections (8 banks of 8 sounds). But beyond that, I don’t know if I’ve ever found octal being used anywhere. (I think this may have been on a Kawai K1/K4 synthesizer).
Anyone have any other examples?