Hexadecimal
Hexadecimal (often abbreviated hex) is a base 16 number system, written using the symbols 0-9 and A-F. It is a useful system in computers because there is an easy mapping from four bits to a single hex digit. Thus one can represent every byte as two consecutive hexadecimal digits. Compare the binary, hex and decimal representations:
bin hex dec 0000 = 0 = 0 0001 = 1 = 1 0010 = 2 = 2 0011 = 3 = 3 0100 = 4 = 4 ... 1001 = 9 = 9 1010 = A = 10 1011 = B = 11 ... 1111 = F = 15
So the the binary representation for 79 (0100 1111) can be written as 4F.
There are many ways to denote hexadecimal numbers, used in different languages:
- C and languages derrived from it (like Java) prefix hexadecimal numbers with '0x', e.g. 0x5A3.
- Pascal and some Assemblers indicate hex by an appended 'h' (if the number starts with a letter, then also with a preceding 0), e.g. 0A3Ch, 8Eh.
- AT&T Assembly and some versions of BASIC uses a prefixed '$', e.g. $D7E.
- Some versions of BASIC prefix hexadecimal numbers with "&h", e.g. &h7fff.
- When talking about number systems other than base-10, or numbers in multiple bases, mathematicians write the base in subscript after the number, e.g. C3816 (sometimes they also use the Greek alphabet rather than the Latin one to denote digits greater than 9, so this example may also be written as γ3816).
There's no single agreed-upon standard, so in most cases one can see the designations above used all at once (sometimes even inside the same paper). However, as they are quite unambiguous, little difficulty arises from this.
The word "hexadecimal" is strange in that "hexa" is derived from Greek and "decimal" is derived from Latin. The original term was the fully-Latin "sexidecimal", but that was changed because some people thought it to be too racy.
Fractions
The hexadecimal system is quite good for forming fractions:
1/2 = 0.8 1/3 = 0.5555 recurring 1/4 = 0.4 1/5 = 0.3333 recurring 1/6 = 0.2AAAA recurring 1/8 = 0.2 1/A = 0.19999 recurring 1/C = 0.15555 recurring 1/F = 0.1111 recurring
Because the base is a square, hexadecimal fractions have an odd period much more often than decimal ones.
See number system for a list of other special base systems.