Why does adding `0.1` ten times not equal `1.0`, and what does the computer storing numbers in base 2 have to do with it?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
In base 2 each place is a power of two and each digit is 0 or 1, so a binary number is just the sum of the place values whose digit is 1.
In the pattern 1011 the 1 bits sit at the places worth 2 ** 3, 2 ** 1 and 2 ** 0. Add up exactly those place values and assign the decimal total to binary_value.
Floating-point error and equality of floats
Write the loop that adds 0.1 ten times, record the resulting 0.9999999... next to 0.1 * 10, and state the rule against comparing floats with ==.
Base 2 and two-state hardware
State that numbers are stored in base 2, and record the two-state hardware examples given: magnetic spin up or down, voltage low or high.
Decimal to binary by largest powers of 2
Write the base-10 decomposition of 1507 as digits times powers of 10, then build 1507 as with zeros elsewhere.
The successive-division algorithm
Trace 1507 through repeated integer division by 2, prepending each remainder in turn, and match the resulting bit string to the powers-of-2 answer.