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.
8 else:—binaryClick 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.
- Buggy — builds the columns small-to-big (
1, 2, 4, 8) and greedily takes the smallest that fits. It spends 13 on the little columns, leaves the 8s column empty, and theremainder never reaches 0 — so it lands on the wrong number. - Procedural — walks biggest to smallest: 8 fits in 13 (5 left), 4 fits in 5 (1 left), 2 does not fit, 1 fits — so 13 is
1101, which is exactly 8 + 4 + 1.
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.