1bin(173)2hex(173)3oct(173)40xFF5int('ad', 16)×1001×107×130101010101010101×16×10
Digit cells: the place value on top, the digit belowBit lamps: a lit lamp is a 1, a dark lamp a 0Calculator: the working value of the current sum or divisionPython card: the built-in functions that do each conversionThe same number, 173, in three rows that share one ones column. Each cell's place value stands above its digit: ×100 ×10 ×1 in decimal, 128 down to 1 in binary, ×16 ×1 in hex. Tokens hop along dashed trails: digit × place into the calculator; remainders of repeated division by 2 into the bits, right to left; groups of four bits into the hex cells (1010 = A, 1101 = D); groups of three into octal digits (0o255). A group of four bits is called a nibble. A byte is eight bits, so two hex digits always describe exactly one byte: 00 to FF, which is 0 to 255.

Place value

  1. In 173 each digit's place sets its worth: 1 hundred, 7 tens and 3 ones. Moving one place left multiplies the worth by 10. Add digit × place: 100 + 70 + 3 = 173.

Decimal to binary

Hex and octal

In code

Try it in the Python prompt

;; step 1/10 · Base 10: place value
>>> 1*100 + 7*10 + 3*1
173
>>> 10**2, 10**1, 10**0      # the decimal places
(100, 10, 1)

Repeated division works for any base: divide by the base, keep the remainder, and repeat with the quotient until it is 0. The remainders, read from the last one to the first, are the digits. Python prints hex digits in lower case ('0xad'); 0xAD and 0xad are the same number. 0b, 0o and 0x are prefixes that say which base a literal is written in.