Decimal to binary

Binary looks mysterious, but it is just place value with a different base. In decimal the columns are 1, 10, 100…; in binary they are powers of two: 1, 2, 4, 8…. To write a number, walk the columns from biggest to smallest and take each one that fits, subtracting as you go.

Write the number 13 in binary by filling the powers-of-two columns: 8, 4, 2, 1.

Decimal to binary — columns the wrong way round execution-derived · CPython
8    else:
same data, two zoom levels
state after line 1 runs
remaining: 13
= binary
step 1 / 19

Click a line, drag the slider, or use the keys.

What you are looking at

The number 13 and four place-value columns. Binary is just place value in base two: each column is a power of two, and the order you walk them in is the whole trick.

There is no separate "binary visualizer" here: this is a real Python program, traced line by line like every other lesson. That is the whole idea — data is just more programs to trace. See how GlassBox stays honest.