Since 16 = 2⁴, every hexadecimal digit stands for exactly four bits. That makes conversion between binary and hex a pure lookup, with no arithmetic.
Binary → hex:
- Split the bits into groups of 4, starting from the right (the LSB).
- If the leftmost group is short, pad it with zeros on its left.
- Replace each group with its hex digit, from
0000= 0 to1111= F.
Hex → binary: replace each digit with its 4-bit nibble, keeping all four bits (3 is 0011, not 11). You may drop leading zeros of the whole number afterwards.
Why from the right? Each hex digit covers a fixed set of weights: the rightmost covers 8, 4, 2, 1, the next covers 128, 64, 32, 16, and so on. Grouping from the left misaligns every group, and padding on the right adds zeros to the end of the number, doubling it each time.
Because it's so easy, hex is the normal way for people to write binary. Octal works the same way with 3-bit groups (binary octal conversion).