There are several reasons why you need a hexadecimal representation in decimal value. The most common in calculations are bit fields . Several people have already mentioned color codes, for example:
red = 0xFF0000 // 16711680 in decimal green = 0x00FF00 // 65280 in decimal blue = 0x0000FF // 255 in decimal
Please note that this color representation is not only more intuitive than trying to figure out what color a random integer can be, e.g. 213545, but it also takes up less space than a 3-tuple, e.g. (125, 255, 0) , representing (R,G,B) . A hex view is an easy way to abstract the same idea as a 3-tuple, with much less overhead.
Remember that there are many applications in bit fields, consider the spacetime bit field:
Represents x coordinate | Represents y coordinate | | Represents z coordinate | | | Represents t | | | | 1A 2B 3C 4D
Another reason someone can use hexadecimal values ββis because it is sometimes easier to remember (and represent) a binary digit as two characters rather than three. Consider the instructions for using x86 . I know that 0xC3 ret ; Itβs easier for me to remember the 00-FF hexadecimal numbers, not the 0-255 decimal places (I looked at it, and ret ends 195 ), but your mileage may vary. For example, this is the code from a project I was working on:
public class x64OpcodeMapping { public static final Object[][] map = new Object[][] { { "ret", 0xC3 }, { "iret", 0xCF }, { "iretd", 0xCF }, { "iretq", 0xCF }, { "nop" , 0x90 }, { "inc" , 0xFF }, }; }
There are clear advantages to using hexadecimal notation (not to mention consistency). Finally, as Obicer mentions, hexadecimal codes are often used as error codes. Sometimes they are grouped in half. For instance:
0x0X = fatal errors 0x1X = user errors 0x2X = transaction errors
In such a scheme, the minimum list of errors will look like this:
0x00 = reserved 0x01 = hash mismatch 0x02 = broken pipe 0x10 = user not found 0x11 = user password invalid 0x20 = payment method invalid
Please note that this also allows you to add new errors to 0x0X , if necessary. This answer turned out to be much longer than I expected, but I hope I shed some light.