Base ten comes from fingers
There is no mathematical reason we use base ten; it settled that way because we have ten fingers. A base is an agreement about when to carry to the next place, and the number itself is the same however it is written. 255, 0xFF and 0b11111111 are one number written three ways.
Why machines use binary
The states an electronic circuit can distinguish reliably are high voltage and low voltage. Distinguishing ten levels would be far more vulnerable to noise. Computers therefore express everything in two states, and that notation is binary. A bit is one place holding one of those two states.
Why hexadecimal is convenient
Binary runs to too many digits for people to read. Sixteen is two to the fourth power, so four binary digits map exactly onto one hexadecimal digit. Converting between them therefore needs no arithmetic, only splitting into groups of four. That is why colour codes and memory addresses are written in hexadecimal.
- Binary 1111 = hex F = decimal 15
- Eight binary digits = two hex digits = one byte
- Hex uses A to F after 0 to 9
- Octal splits into groups of three and is used for file permissions
Marking the base
Written as just 10, it could be ten in decimal or two in binary. Programming therefore marks hexadecimal with 0x and binary with 0b. Errors from mistaking the base of an unprefixed number are hard to find, so making the notation explicit is safer.
Converting by hand
To convert decimal to another base, divide repeatedly by that base and read the remainders backwards. To convert back, multiply each digit by the base raised to its position and add. Memorising a few common values removes the need to calculate in most situations.
🌍 Search the web for this
Each button runs this keyword on that search engine