2AF₁₆ → octal — number base conversion

exam standardroute through binary, not decimal

Answer

1257

Why this example is worth doing

Converting between two non-decimal bases is done by going through binary, not through decimal: expand each hex digit to four bits, then regroup those bits in threes for octal. It is faster and it cannot go wrong arithmetically, since neither step involves any addition. The page shows the intermediate bit string explicitly because the regrouping — from fours to threes, with the boundaries in different places — is the whole content of the exercise.

Try your own input in the Binary ⇄ decimal ⇄ hex ⇄ octal. Convert between any two bases, integers and fractions, with the positional working.

How the answer is reached

Base 16 to base 8

Convert 2AF from base 16 to base 8. The sign is carried across unchanged; only the magnitude is converted.

Positional expansion of the input — Base 16 to base 8
digitvalueweightweight (base 10)digit x weight
2216^2256512
A1016^116160
F1516^0115
total687

Integer part: divide by 8 and read the remainders bottom to top.

Read the last column bottom to top. ↑ — Base 16 to base 8
ndivide byquotientremainder
687687 ÷ 8857
8585 ÷ 8105
1010 ÷ 812
11 ÷ 801

2AF (base 16)1257 (base 8)

Compare with

Open this example in the Binary ⇄ decimal ⇄ hex ⇄ octal

The field arrives filled in with this example’s input.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • Fractions are converted digit by digit and shown to a stated number of places rather than rounded silently.

Sources

  • Knuth, The Art of Computer Programming, Vol. 2, §4.1 “Positional Number Systems” (1997)
  • IEEE 754-2019, Standard for Floating-Point Arithmetic