Power term base conversion
Power term base conversion
Power term base conversion · p₁,d₁,p₂,d₂,…
- 104 bytes
- COMP mode
Worked examples
Example 1
A database stores identifiers in hexadecimal. One identifier has the value N = 8^7. Which of the following is equal to N?
Answer
Standard solution (without a calculator)
- Write as a power of 2: 8 = 2³, so N = (2³)⁷ = 2^(3×7) = 2²¹.
- Group the bits in fours: 16 = 2⁴ and 21 = 4 × 5 + 1, so 2²¹ = 2¹ × (2⁴)⁵ = 2 × 16⁵.
- Read the digits: the only non-zero hexadecimal digit is 2, at position 5, so N = 200000₁₆.
- Choose the option: the options have coefficients 1, 2, 4 and 8 on 16⁵; only 2 × 16⁵ equals 2²¹. The answer is B.
Example 2
A coding system uses the value N = 14 × 16¹². Express N as a sum of distinct non-negative integer powers of 2, listing the exponent of every non-zero binary digit.
Answer
Standard solution (without a calculator)
- Change to powers of 2: 16¹² = (2⁴)¹² = 2⁴⁸, so N = 14 × 2⁴⁸.
- Split the coefficient: 14 = 8 + 4 + 2 = 2³ + 2² + 2¹, that is 1110₂.
- Shift each exponent by 48: N = (2³ + 2² + 2¹) × 2⁴⁸ = 2⁵¹ + 2⁵⁰ + 2⁴⁹.
- List the digits: the non-zero binary digits are 1 at positions 49, 50 and 51; every other position is 0.
Example 3
A communication device records N = 35 × 2¹¹ as a positive hexadecimal integer. (a) List the exponent and the decimal digit value of every non-zero hexadecimal digit. (b) Write N in hexadecimal.
Answer
Standard solution (without a calculator)
- Find the starting position: 11 = 4 × 2 + 3, so 2¹¹ = 2³ × 16² = 8 × 16², and N = (35 × 8) × 16² = 280 × 16².
- Divide the coefficient by 16: 280 = 17 × 16 + 8 and 17 = 1 × 16 + 1, so 280 = 1 × 16² + 1 × 16 + 8.
- Restore the positions: N = (16² + 16 + 8) × 16² = 1 × 16⁴ + 1 × 16³ + 8 × 16². The non-zero digits (p, d) are (2, 8), (3, 1) and (4, 1); positions 1 and 0 hold 0.
- Write the numeral: from position 4 down to 0 the digits are 1, 1, 8, 0, 0, so N = 11800₁₆.
- Check in decimal: 35 × 2048 = 71680 and 65536 + 4096 + 2048 = 71680.
When to use it
Terms such as 8^7 or 14 × 16^12 can be rewritten as N = A × 2^X. For the base b = 2^B, the program splits X = BY + r, so N = (A × 2^r) × b^Y, then divides A × 2^r repeatedly by b to find the digits from position Y upwards.
Enter the known values
- A: positive integer coefficient; X: exponent of 2 (an expression such as 3×7 may be typed); B: bits per target digit — 1 binary, 2 base four, 3 octal, 4 hexadecimal. Enter 4 for hexadecimal, not 16.
- Rewrite the term as A × 2^X first: 8^7 = 1 × 2^(3×7) and 14 × 16^12 = 14 × 2^(4×12).
Read the results
- Results come in pairs from the lowest non-zero digit upwards: first the position exponent p, then the digit value d in decimal. Press EXE at each Disp screen; the last digit value is the final screen.
- Positions that are not shown hold 0. Write the full numeral from the highest position down, and write digit values 10–15 as A–F in hexadecimal.
Question types
- Original practice in HKDSE Mathematics Compulsory Part style on binary and hexadecimal numbers, such as choosing the hexadecimal form of a power or writing a number as a sum of powers of 2. Base 4 and octal work the same way.
Before you start
- Use COMP mode and an empty program area with at least 104 bytes (P1–P4 share 680 bytes). The examples use P2. A, B, C, X and Y are overwritten.
- A must be an integer from 1 to 9999999999; a zero term needs no conversion. X must be an integer from 0 to 99. Negative coefficients, decimals and negative exponents are not handled, and the program does not check its inputs.
- B is the number of bits per target digit: 1 binary, 2 base four, 3 octal, 4 hexadecimal. Entering 16 does not mean hexadecimal.
- Only non-zero digits are shown, as pairs p then d from low to high; position 0 is the units digit. Write the full numeral in reverse order and fill missing positions with 0.
- One term is converted per run. A long numeral can be done one non-zero digit at a time: for a hexadecimal digit at position p, enter X = 4×p. To add several terms, add digits in the same position and carry yourself; do not place outputs of separate runs side by side.
- The program uses Fix 0 for whole-number rounding and restores Norm 1 at the end. At a Disp screen EXE continues; at the final screen EXE restarts and AC leaves. If you stop early with AC, Fix 0 stays on; set Norm 1 yourself.
Checking access…