Best afterDecimal to binary

Binary to decimal

Going from binary back to decimal is one loop: read the bits left to right, and at each step double what you have and add the next bit. The whole lesson hides in one number — the base you multiply by. Get it wrong and 1101 comes out as eleven hundred and one instead of thirteen.

Read a binary number left to right and work out the decimal value it represents.

Binary to decimal — reading it as base ten execution-derived · CPython
variables
state after line 1 runs
variablevalue
bits[1,1,0,1]
step 1 / 11

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

What you are looking at

The bits are 1 1 0 1. In binary the places are 8 4 2 1, so this is 8 + 4 + 0 + 1 = 13. The loop builds that up by doubling: 0 → 1 → 3 → 6 → 13.

Every state you see came from running the program under CPython's tracer at build time — see how GlassBox stays honest.