Converting a Number in Another Base to Decimal
Converting a Number in Another Base to Decimal
Convert a short binary, hexadecimal or other-base number to decimal, one digit at a time.
- 30 bytes
- COMP mode
Worked examples
Example 1
Sensor code: a sensor stores a status code in binary as 110101011₂. What is the decimal value of this status code?
Answer
Standard solution (without a calculator)
- Place values from the right: there are nine binary digits; the rightmost is position 0 and the leftmost position 8. The non-zero digits are in positions 8, 7, 5, 3, 1 and 0.
- Expand in powers of 2: 110101011₂ = 2⁸ + 2⁷ + 2⁵ + 2³ + 2¹ + 2⁰ = 256 + 128 + 32 + 8 + 2 + 1 = 427, so the answer is B.
- Check by grouping: in fours from the right, 1 | 1010 | 1011 is hexadecimal 1AB, and 1 × 16² + 10 × 16 + 11 = 256 + 160 + 11 = 427.
Example 2
Chip code: a chip’s identification code is 2AF₁₆. What is the decimal value of this code?
Answer
Standard solution (without a calculator)
- Letters to digit values: in hexadecimal A = 10, B = 11, C = 12, D = 13, E = 14, F = 15, so the three digits are 2, 10 and 15.
- Add by place value: 2AF₁₆ = 2 × 16² + 10 × 16 + 15 = 512 + 160 + 15 = 687, so the answer is D.
- Check by division: 687 = 42 × 16 + 15 and 42 = 2 × 16 + 10; reading from the top gives 2, 10, 15, i.e. 2AF₁₆.
Example 3
Block code: a database ID satisfies 3D700C900005₁₆ = k × 16⁹ + 201 × 16⁵ + 5, where k is a decimal integer. The ID splits as 3D7 | 00 | C9 | 0000 | 5. Find k.
Answer
Standard solution (without a calculator)
- Place value of each block: 3D7 is followed by nine digits (00, C9, 0000, 5), so the first block is 3D7₁₆ × 16⁹. C9 is followed by five digits (0000, 5), so the middle block is C9₁₆ × 16⁵. The last digit is 5.
- Find k: D = 13, so k = 3D7₁₆ = 3 × 16² + 13 × 16 + 7 = 768 + 208 + 7 = 983, and the answer is A. Only the three-digit block 3D7 is entered in the program.
- Check the rest: C9₁₆ = 12 × 16 + 9 = 201, the middle coefficient, so the whole ID is 983 × 16⁹ + 201 × 16⁵ + 5. As 16⁹ ≠ 0, k has only one possible value.
Grouping only shortens the number to convert: the zeros after a block stay in the ID and fix its place value — 16⁹ and 16⁵ come from the digits on the right.
When to use it
DSE multiple-choice questions on number bases ask for the decimal value of a binary or hexadecimal number, or for a coefficient in an expansion such as k × 16⁹ + …. 020 reads a short group digit by digit from the left and shows its decimal value; a long number is first split into short groups.
What it is for
- The decimal value of a short binary, base-4, octal, decimal or hexadecimal number
- The coefficient of one block of a long hexadecimal number (such as 3D7 in 3D7 × 16⁹)
- Checking options by converting the numbers in them
What you enter
- B: the base (2, 4, 8, 10 or 16)
- X: the number of digits in this group
- Then each digit from the left, one per prompt; hexadecimal A–F are typed as 10–15, and every zero is typed
What it shows
- One result: the decimal value of the group
- No pauses on the way
- Each further group needs its own run
Check before use
- Use COMP mode; the walkthrough uses P1. It takes 30 of the 680 bytes shared by P1–P4, and the angle setting does not matter.
- Bases 2, 4, 8, 10 and 16 are supported. The number of digits is a whole number of at least 1, and each digit a whole number from 0 to base − 1 (A–F as 10–15).
- The group’s decimal value N must satisfy 0 ≤ N < 10¹⁰ so that Norm 1 shows every digit. Safe maximum lengths: binary 33 digits, base 4 16, octal 11, decimal 10, hexadecimal 8.
- Type one digit per prompt; zeros in the middle are typed one by one. After the stated number of digits the program ends by itself, with no end code.
- Type a value at every prompt, including 0. The program does not check its inputs: check the base, the digit count, every digit and the size of the group first.
- Split a longer number into short groups and keep each group’s position on paper. The program gives each group’s value; the place values, the full expression and any change of base are worked on paper.
- It uses B, D, X, Y and Ans, resets the running total to 0 on every run and sets Norm 1. After the answer the program has finished: EXE runs it again, AC leaves.
Checking access…