Carrying and Borrowing Column by Column
Carrying and Borrowing Column by Column
Turn column coefficients into proper digits in any base by carrying and borrowing; it also converts a decimal whole number.
- 92 bytes
- COMP mode
Worked examples
Example 1
A sensor turns the decimal status number 57 into binary. Which binary number has the same value as 57?
Answer
Standard solution (without a calculator)
- Highest power of two not above 57: 2⁵ = 32 and 2⁶ = 64 > 57, so the highest non-zero place is position 5. Take away 32, leaving 25.
- Split the remainder: 25 = 16 + 9 = 16 + 8 + 1, so 57 = 2⁵ + 2⁴ + 2³ + 2⁰. From position 5 down to 0 the digits are 1, 1, 1, 0, 0, 1.
- Write it in binary and check: 111001₂, so the answer is B. Check: 1 × 32 + 1 × 16 + 1 × 8 + 0 × 4 + 0 × 2 + 1 = 57.
Example 2
A data ID has the value 14 × 16 + 20. Which hexadecimal number represents this ID?
Answer
Standard solution (without a calculator)
- Split the units coefficient: a hexadecimal digit is 0 to 15. 20 = 1 × 16 + 4, so 4 stays in the units and 1 is carried to the sixteens.
- Add to the next place and use a letter: 14 × 16 + 20 = (14 + 1) × 16 + 4 = 15 × 16 + 4, and the digit 15 is written F in hexadecimal.
- Answer and check: F4₁₆, answer C. In decimal: 14 × 16 + 20 = 224 + 20 = 244, and F4₁₆ = 15 × 16 + 4 = 244.
Example 3
A hexadecimal counter holds 2 × 16 units; 3 units are taken away. What hexadecimal number should it show?
Answer
Standard solution (without a calculator)
- Borrow one sixteen: 2 × 16 − 3 = 1 × 16 + (16 − 3). The borrowed sixteen is 16 units, so 13 are left in the units.
- Write a proper digit: 13 is the hexadecimal digit D, so the result is 1 × 16 + 13 = 1D₁₆, answer A.
- Check in decimal: 32 units − 3 = 29, and 1D₁₆ = 16 + 13 = 29.
When to use it
DSE number bases questions often mix powers of one base, such as 14 × 16 + 20 or 2 × 16 − 3, where a column holds more than B − 1 or a negative amount. 023 tidies every column into a proper digit from 0 to B − 1, carrying up or borrowing as needed. With a single column it also converts a decimal whole number into another base.
What it is for
- Expressions in one base whose columns need carrying or borrowing
- A decimal whole number up to 10⁹ in base 2, 4, 8, 10 or 16 (Y = 0, c0 = the number)
- Checking multiple-choice options
What you enter
- B: the base (2, 4, 8, 10 or 16); Y: the highest power entered, from 0 to 99
- c0, c1, …, cY at each A?: the coefficient of each column, from the 0th power up; 0 for a missing column
- Whole-number coefficients with |c| ≤ 10⁹; terms in one column may be combined, e.g. 5−1
What it shows
- Pairs of screens: the position p, then the digit d (d × Bᵖ), from the lowest place up
- Only non-zero digits; fill the places not shown with 0
- A final lone 0 means the program has finished
Check before use
- Create the program in COMP; P3 is suggested. It takes 92 of the 680 bytes shared by P1–P4.
- Enter the base B first (2, 4, 8, 10 or 16), then the highest power entered, Y, a whole number from 0 to 99.
- Then enter c0, c1, …, cY in order, from the 0th power. Each is a whole number of absolute value at most 10⁹. Enter 0 for a missing column; terms in the same column can be combined first or typed as a whole-number expression such as 5−1.
- Each column means c × Bᵖ. The highest power entered is not the answer’s highest place: if a carry remains, the program extends by itself without asking for more coefficients.
- The whole number made by all the columns must be non-negative. Coefficients and carries along the way may be negative — that is how borrowing works. All terms must already be in the same base B; the program does not take powers of another base.
- Results and coefficient prompts alternate. Results come in pairs: first the position p, then the digit d, meaning d × Bᵖ. Only non-zero digits are listed, from the lowest place up; fill the places not listed with 0. In base 16 write 10–15 as A–F.
- The final lone 0 is a completion mark, not another digit. If the whole number is zero, only this 0 appears. EXE on the final screen runs the program again; AC leaves.
- Enter a value at every prompt: a blank EXE keeps the old value and cannot stand for zero or for “done”. The program overwrites A, B, M, X and Y, and sets Norm 1 when it finishes normally.
- To keep it short there are no extra input checks. Decimals, a wrong base, out-of-range coefficients or a negative total are not guaranteed to be rejected; a negative total may never finish — press AC to stop it.
Checking access…