0xCONVERTER-HEX

Guide

The Hexadecimal Number System

Place value, counting, arithmetic and signed representation in base 16.

Positional notation

Hexadecimal is positional, which means a digit's value depends on where it sits. Every position is worth sixteen times the position to its right.

PowerHexDecimal
16011
1611016
162100256
16310004,096
1641000065,536
1651000001,048,576
166100000016,777,216
16710000000268,435,456
1681000000004,294,967,296

To evaluate any hex number, multiply each digit by its place value and add. That is the complete definition of the system.

1A2B

  1 × 4096 = 4096
  A ×  256 = 2560
  2 ×   16 =   32
  B ×    1 =   11
                ------
                  6699

Counting in hex

Counting is where intuition either clicks or does not. The sequence runs normally to 9, continues through the letters, and only then rolls over.

0 1 2 3 4 5 6 7 8 9 A B C D E F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 ...
...
F0 F1 ... FD FE FF
100

Three landmarks: 10 is sixteen, FF is 255, and 100 is 256. Once those three feel natural, everything else follows.

Why sixteen and not some other base

The choice is not arbitrary. Bases that are powers of two align with binary; bases that are not do not.

BaseBits per digitAligns with a byte?
21Yes — but eight digits per byte is unreadable
83No — 8 does not divide by 3
10~3.32No — not a power of two at all
164Yes — exactly two digits per byte
325No — 8 does not divide by 5

Only base 16 gives a whole number of digits per byte while staying compact. That is the entire reason it won.

Arithmetic

Every rule from decimal carries over. Only the rollover point changes: sixteen rather than ten.

OperationDecimalHex
Carry whenA column reaches 10A column reaches 16
Borrow brings1016
Multiply by baseAppend a 0Append a 0 (multiplies by 16)
Divide by baseDrop last digitDrop last digit (divides by 16)
addition        subtraction
  2F              40
+ 1A            - 1B
----            ----
  49              25

F + A = 25      0 - B needs a borrow
25 - 16 = 9     16 - 11 = 5
carry 1         4 becomes 3, 3 - 1 = 2

The hex calculator shows this working for any pair of values.

Bit widths

Because every digit is four bits, digit count and bit count are interchangeable.

Hex digitsBitsMax unsignedSigned range
1415−8 to 7
28255−128 to 127
41665,535−32,768 to 32,767
8324,294,967,295±2.1 billion
16641.8 × 1019±9.2 quintillion

Signed numbers

Hex has no minus sign in practice. Negative values are represented using two's complement at a fixed bit width, which means the width must be known before the value can be read.

  1. Fix the width — 8, 16, 32 or 64 bits.
  2. If the leftmost bit of that width is 0, the value is positive and reads normally.
  3. If it is 1, the value is negative. Subtract 2width to find it.
FF at 8 bits   → top bit set → 255 - 256 = -1
FF at 16 bits  → top bit clear → 255
80 at 8 bits   → top bit set → 128 - 256 = -128
7F at 8 bits   → top bit clear → 127

The same eight bits mean 255 or −1 depending entirely on how the surrounding code declares them. The hex to decimal converter switches between readings.

Fractions

Hex fractions exist and follow the same rule: digits after the point are worth 1/16, 1/256, 1/4096 and so on. 0.8 in hex is one half, and 0.4 is one quarter.

They are rare in practice because floating-point numbers use a different representation altogether — a sign, an exponent and a mantissa, all packed into bits and usually displayed in hex only when someone is debugging the bit pattern itself.

Frequently asked questions

How does place value work in hexadecimal?

Each position is worth sixteen times the position to its right: 1, 16, 256, 4096 and so on. Multiply each digit by its place value and add.

What comes after F in hex?

10, which means sixteen. The sequence is 0 to 9, then A to F, then 10.

Why is base 16 used rather than base 8 or 32?

Sixteen is the only convenient base where one digit is exactly four bits and one byte is exactly two digits. Eight and thirty-two do not divide into a byte evenly.

How does hex arithmetic differ from decimal?

Only in the rollover point. A column carries at sixteen rather than ten, and a borrow brings sixteen across.

How are negative numbers written in hex?

Using two's complement at a fixed bit width. At 8 bits, -1 is FF; at 32 bits the same value is FFFFFFFF.

Can hexadecimal have a fractional part?

Yes. Digits after the point are worth one sixteenth, one 256th and so on. It is rare, because floating point uses a different representation.