021Mathematics · Number bases

Long Whole Numbers in Another Base, Digit by Digit

Long Whole Numbers in Another Base, Digit by Digit

Convert a whole number to base 2–16, one digit per screen, from the highest place down.

  • 58 bytes
  • BASE mode
01

Worked examples

Example 1

An electronic counter at a school event has recorded 2025 entries. Which of the following is this decimal number written in binary?

  1. A.11111011001₂
  2. B.11111101001₂
  3. C.11111110001₂
  4. D.11111101010₂
Answer
B 2025₁₀ = 11111101001₂ (11 digits)
Standard solution (without a calculator)
  1. Highest place: 2¹⁰ = 1024 and 2¹¹ = 2048; since 1024 ≤ 2025 < 2048, the highest place is 2¹⁰ and the answer has 11 digits, from 2¹⁰ down to 2⁰.
  2. Take out the powers of two: 2025 − 1024 = 1001; 1001 − 512 = 489; 489 − 256 = 233; 233 − 128 = 105; 105 − 64 = 41; 41 − 32 = 9. 9 < 16, so the 2⁴ place is 0; 9 − 8 = 1 puts 1 in the 2³ place; the 2² and 2¹ places are 0; the 2⁰ place is 1.
  3. Write the digits in place order: 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1 — that is 11111101001₂. The zeros in the middle hold places and cannot be left out.
  4. Check the options: 1024 + 512 + 256 + 128 + 64 + 32 + 8 + 1 = 2025. Options A–D are 2009, 2025, 2033 and 2026, so only B matches.
Do it on the calculator

Example 2

A robotics contest turns the decimal ID 1337 of a device into a binary ID. Which of the following is correct?

  1. A.10100110101₂
  2. B.10101011001₂
  3. C.10100111001₂
  4. D.10100111010₂
Answer
C 1337₁₀ = 10100111001₂ (11 digits)
Standard solution (without a calculator)
  1. Highest place: 1024 ≤ 1337 < 2048, so the highest place is again 2¹⁰; 1337 − 1024 = 313.
  2. Zero places in the middle: 313 < 512, so the 2⁹ place is 0; 313 − 256 = 57 puts 1 in 2⁸. 57 is below 128 and 64, so 2⁷ and 2⁶ are 0. 57 − 32 = 25, 25 − 16 = 9 and 9 − 8 = 1, so 2⁵, 2⁴ and 2³ are 1.
  3. The last three places: 1 is below 4 and 2, so 2² and 2¹ are 0 and 2⁰ is 1. In order: 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, i.e. 10100111001₂.
  4. Check: 1024 + 256 + 32 + 16 + 8 + 1 = 1337. The options are 1333, 1369, 1337 and 1338, so only C matches.
Do it on the calculator

Example 3

A sensor has recorded 512 signals and then receives one more. It shows the running total as an unsigned binary number without extra leading zeros.
(a) Write the updated decimal total in binary.
(b) How many digits does the answer have, and how many zeros lie between the two 1s?

Answer
(a) 513₁₀ = 1000000001₂ (b) 10 digits, 8 zeros between the 1s
Standard solution (without a calculator)
  1. The number to convert: 512 + 1 = 513.
  2. Place values: 512 = 2⁹, so 513 = 2⁹ + 2⁰. The highest and lowest places are 1; every place from 2⁸ to 2¹ is 0.
  3. Full answer: from 2⁹ to 2⁰ the digits are 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, so 1000000001₂ — 10 digits, with 8 zeros between the two 1s.
  4. Calculator range: this is an ordinary unsigned binary number. The built-in Bin uses 10-bit two’s complement and stops at 511, so 513 is out of its range; the program stays in Dec and shows the digits one by one.
Do it on the calculator
02

When to use it

DSE number bases questions ask for a decimal number written in binary or another base. The calculator’s built-in Bin only reaches 511, so longer binary numbers do not fit. 021 stays in decimal and shows the digits one per screen, from the highest place to the lowest, so you copy them in reading order — no reversing and no missing zeros.

What it is for

  • A whole number from 0 to 2147483647 written in base 2 (up to 31 digits) or any base up to 16
  • Checking multiple-choice options by converting a candidate
  • The same number in another base (leave X? blank next time)

What you enter

  • X: the whole number in base 10 (kept, so EXE alone reuses it next time)
  • B: the base; it is preset to 2, so for binary press EXE without a number
  • For bases above 10, read the values 10–15 as A–F

What it shows

  • One digit per screen with Disp, from the highest place; press EXE for the next
  • The last digit has no Disp: copy it and stop
  • Each screen shows the digit’s value in base 10 — 10, 11, … 15 mean A, B, … F

Check before use

  • Create the program in BASE mode; the Dec at the start makes it read decimal input. Do not run it in COMP. The angle setting does not matter. The example uses an empty P1; if P1 holds a program, use another empty area and change the keys, rather than clearing P1 with the set-up keys.
  • X must be a whole number from 0 to 2147483647 and B a whole number from 2 to 16. There are no range checks, to save bytes: do not enter negatives, decimals or a base of 0 or 1. If a wrong input keeps it running, press AC and start again.
  • One digit is shown at a time. At each Disp screen copy the digit and press EXE; the last digit has no Disp — copy it too, then stop. EXE on the last screen runs the program again. Do not do other calculations while the digits are shown, as that would change Ans.
  • B is reset to 2 on every run; for another base enter it at B?. Base 10 just shows the decimal number digit by digit.
  • Each screen is the digit’s value in base 10. For bases above 10, 10–15 stand for A–F: X = 43981 with B = 16 gives 10, 11, 12, 13 — write ABCD, not 10111213. In binary every screen is 0 or 1.
  • Under the calculator’s BASE rules, Bin uses 10-bit two’s complement, so non-negative values only reach 511 (512 is already out of range). This program works in Dec throughout, so a binary answer can have up to 31 digits. For short conversions within 0–511, and for ordinary Dec ↔ Hex, the built-in BASE keys are quicker.
  • BASE mode has no power key, so 2^10 cannot be typed there. For a question with powers, find the decimal value in COMP first and enter that whole number at X?; do not type scientific functions or powers at the prompts.
  • The program turns one decimal whole number into another base. It does not read a whole binary string as input and cannot handle integers above 2147483647.

Sign in to unlock the full programme

Checking access…

The programme code and appendix unlock together.

Checking access…

Sign in to unlock the full programme

Checking access…

The programme code and appendix unlock together.