Octal System Conversion

49 Views Asked by At

So I am trying to change base ten 1,398 to an octal equivalent. I had assumed that I would find it by taking 1,398 and changing it like base-four. So 1,398 is $1*8^3 + 3*8^2 +9*8^1 + 8*8^0*$ or $512+192+72+8=784$ but I guess the answer is 2566. Where am I wrong?

2

There are 2 best solutions below

6
On

Well, you want to express $1398$ is the octal base $\{0,\dots,7\}$. That means more precisely that you want to find coefficients $a_0,\dots,a_n$ such that

$$1398=\sum_{i=0}^na_i\cdot 8^i$$

The string $a_0a_1\dots a_n$ is then called the octal representation of $1398$, which is sometimes written as $1398={(a_0a_1\dots a_n)}_8$.

In your concrete example, you can actually see by a little trial and error, that

$$1398=2\cdot 8^3+5\cdot8^2+6\cdot 8^1+6\cdot 8^0$$

and thus $1398=2566_8$.


If you want a more precise method to determine the coefficients for a number $n$ in base $8$, you can follow this:

  1. Start with $i=0$.
  2. Set $a_i = n\;\mathrm{mod}\;8$, the remainder of $n$ after division by $8$.
  3. Set $n = \lfloor n / 8\rfloor$.
  4. Increment $i$ and continue at 2.

Note, that all the things I wrote generalize to different bases, I've just tried to tailor it more to your particular problem.

0
On

To methodically perform the conversion:

$1398 \mod 8 = 6$ ($8^0$ place octal digit)

$\lfloor 1398 / 8 \rfloor = 174$

$174 \mod 8 = 6$ ($8^1$ place octal digit)

$\lfloor 174 / 8 \rfloor = 21$

$21 \mod 8 = 5$ ($8^2$ place octal digit)

$\lfloor 21 / 8 \rfloor =2 $

$2 \mod 8 =2$ ($8^3$ place octal digit)

$\lfloor 2/8\rfloor =0$

So $1398_{10} = 2566_8$