Mathematics Book 1 Exercises: Arithmetic and NumbersMaths Book 1 · Exercises
0 / 0

Workbench / Mathematics Book 1 Exercises: Arithmetic and Numbers

B1·02

Place Value and Bases

Exercises for chapter 2: bundling in any base, why zero and digits below the base matter, lakh and crore, binary and hex, converting both ways with programs that check themselves, the digit-count formula that floating point gets wrong, a strict number reader, and senior exercises on ID schemes, imports and bit flags.

20 topics · ~5 min read
Updated Suggest a correction

Start here: how these exercises work

Write your answer in the box first; hints open one at a time as you write, and the solution a couple of minutes after the last hint. Theory is in your own words, practice and programs come with real output (Python 3.13, Node.js 22), cumulative projects use chapters 1 and 2 together, what the chapter leaves out explains what it skips, and senior exercises put the ideas into designs and reviews.

Theory

T1. Bundles of five

A child counts 87 marbles by tying every 5 loose marbles into a pouch, every 5 pouches into a box and every 5 boxes into a crate. How many crates, boxes, pouches and loose marbles are there? Write the result as a base-5 numeral, and explain in bundle terms why no digit in it can be 5 or more.

T2. A scribe without zero

A Babylonian scribe writes the base-60 digits "1 20" with no sign for an empty place. List three different numbers it could mean, and explain how zero as a digit removes the ambiguity. What ambiguity did the Babylonians still have after they introduced a placeholder used only between digits?

T3. Lakh, crore, million and the comma

A news report says a project costs "₹4,500 crore". Another says "$540 million". Write ₹4,500 crore in rupees with Indian grouping and with international grouping, and in words in both systems. Then explain why the string "1,234" can't safely be read by a program without knowing where it came from.

T4. Why four bits make a hex digit

Explain, using place values, why every group of four binary digits corresponds to exactly one hexadecimal digit, and why no fixed group of binary digits corresponds to one decimal digit. Then convert 10111110111011112 to hex without converting to decimal.

T5. Why digits must be smaller than the base

Someone proposes allowing the "digit" 10 in base 10, written as a single symbol ★. Show that some numbers would then have two numerals, and explain which step of the uniqueness proof breaks.

T6. Odometers and counting

(a) How many digits change when an odometer goes from 1,999 to 2,000? From 99,999 to 100,000 on a six-digit odometer? (b) How many five-digit numbers are there in base 10? In base 2 (counting only those with a leading 1)? (c) Why is the largest four-digit hex number 164−1?

Practice and programs

P1. Conversions by hand

Without a computer: (a) 2026 in base 7; (b) 56237 in decimal; (c) 86,399 seconds as hours, minutes and seconds; (d) 255 in hex and in binary; (e) 3A716 in decimal by Horner's method.

P2. A converter that works for base 60 too

Write digits_in_base(n, b) returning the digits as a list of numbers (so base 60 works, where digits need two decimal characters each), and value(digits, b) that reads them back and refuses a digit that's too big. Check it on (a)–(d) of P1.

P3. The digit-count formula, in floating point

Chapter 2 says n has ⌊log10n⌋+1 digits. Test that formula in Python for every n up to a million, once with math.log(n, 10) and once with math.log10(n), against len(str(n)). Then try n=1015−1. Explain what you find.

P4. A strict number reader in JavaScript

Write strictParse(text, base) that converts the whole text or throws, unlike parseInt. Compare the two on "ff" (16), "101" (2), "12px" (10), "12" (2) and "" (10).

Cumulative projects (chapters so far: 01–02)

C1. Read an amount the way people write it

Write to_paise(text) that reads amounts people actually type ("₹1,23,456.50", "123,456.50", "12 lakh", "1.5 crore", "45") and returns whole paise, and refuses anything it can't read unambiguously: commas in impossible places ("1,2345"), European formats ("1.234,50"), and amounts finer than a paisa ("12.345"). Chapter 1's labels versus quantities and chapter 2's grouping conventions both matter here.

C2. A converter you can trust

Combine P2 and P4 into a small command-line tool: convert 2026 --from 10 --to 7, accepting bases 2 to 36. It must refuse bad digits, accept upper or lower case, and pass a round-trip test: for every base and 10,000 random numbers, converting to the base and back gives the original. What does your test prove, and what doesn't it?

What the chapter leaves out

Mixed-radix systems

Clocks use a different "base" in each place: 60 seconds, 60 minutes, 24 hours, 7 days. That's a mixed-radix system, and every algorithm in the chapter works with a different divisor at each step (P1(c) did this). Old Indian measures (16 annas to a rupee, 12 pies to an anna, before 1957), feet and inches, and even the factorial number system (place values 1!,2!,3!,…, used to number permutations) are all mixed-radix. Uniqueness still holds if each digit is below its own place's radix.

Fractions in a base, and floating point

The chapter keeps to whole numbers. Digits after a point extend place value to b−1,b−2,… (chapter 7 does this for base 10). A computer's floating-point number is a binary numeral with a fixed number of significant bits and a separate exponent saying where the point goes, which is scientific notation in base 2 (chapter 10). The size limits in chapter 1's lab come from the fixed number of bits.

Encodings that look like bases

Base64 (in email attachments and data URLs) and base32 or base58 (in IDs and cryptocurrency addresses) use a base's digits but usually encode bytes, not a single number: base64 turns every 3 bytes into 4 characters of 6 bits each. Base58 removes look-alike characters (0, O, I, l) so people can copy codes reliably. These are notations for data, chosen for the channel they travel through.

Gray code

In ordinary binary, going from 7 (0111) to 8 (1000) changes four bits at once, and a sensor reading the bits mid-change can see anything in between. Gray code orders the numbers so that consecutive values differ in exactly one bit, which is why rotary encoders and some counters use it. It's a different numeral system for the same numbers, chosen because of how the numerals are read.

Senior exercises

S1. Short codes for a billion orders

Your company prints an order code on receipts that customers read aloud over the phone. There will be up to a billion orders. Compare decimal, hexadecimal and a 32-symbol alphabet (Crockford's base32, which drops I, L, O and U): how many characters each needs, and what else you'd design in.

S2. A bank-statement import that silently multiplied by a thousand

A finance app imports CSV statements. After a bank changed its export, one customer's balance showed ₹45.68 instead of ₹45,678.90. Explain what probably happened, and design the import so this class of error can't pass silently.

S3. Permissions packed into a number

A service stores each user's permissions as a 16-bit integer, one bit per permission (read = 1, write = 2, delete = 4, admin = 8, and so on). A support engineer sees the value 13 in the database. What permissions does that user have? Then list the risks of this design and when it's still the right choice.