hexadecimal

From SEGGER Wiki
(Redirected from hex)
Jump to: navigation, search

Hexadecimal (or simply "Hex) is the representation of a number to base 16. Hex number are (in C-language and in a lot of other contexts) denoted by prefixing them by 0x. In general, numbers are represented in decimal format, so base 10. Therefor only 10 different digits exist, 0...9. In hexadecimal, 16 digits are required, so the first six letters of the alphabet are used. Therefor, the digits in hexadecimal are:

Hex digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Converting hex to decimal

Most calculators can easily do it, but it is important to understand how to do it: In any number representation, be it Hex, decimal, octal, binary or any other base, the position value of rightmost (least significant) digit is 1, the next one is n, the next one being n² etc. This means that in decimal, the position values are: 1, 10, 100, 1000, ... In hex, they are 1, 0x10, 0x100, 0x1000, which equals 1, 16, 256, 4096, ...

So 0x25 is 2 * 16 + 5 = 37.

Why hex

Hex is in use in computer programming, as a hex digit can represent 4 bits and is therefor a good choice for displaying numbers in computers, such as addresses.

Example: The number of bytes that can be addressed by a true 16-bit CPU with 16 address bits is 2^16, which is 0x10000 = 65536.