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 Answers
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:
- Start with $i=0$.
- Set $a_i = n\;\mathrm{mod}\;8$, the remainder of $n$ after division by $8$.
- Set $n = \lfloor n / 8\rfloor$.
- 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.
- 4,794
-
So do I need to divide 1398 by 8 for the $a_i*8^i$? So I'd get 174 R6. I don't feel like this is correct. I'm sorry. Your statement about trial and error leave quite a bit to be desired. – K Math Apr 05 '19 at 23:25
-
1@KMath You're totally right. That was a little bit avoidance on my side. I've edited my answer. – blub Apr 05 '19 at 23:32
-
2I can't recall I've ever seen the notation $1398_8$ used to mean the octal notation for the number whose decimal notation is "1398". Usually $1398_8$ would mean the number whose octal notation is "1398" -- except there is no such thing because 8 is not a valid octal digit. – hmakholm left over Monica Apr 05 '19 at 23:40
-
@HenningMakholm That is some unfortunate mistyping, I'll edit my answer. – blub Apr 05 '19 at 23:44
-
Step 3 in your algorithm should be something like $n= \lfloor n/8 \rfloor$, in order to get rid of the fractional part. – Andy Walls Apr 06 '19 at 00:02
-
@AndyWalls Ah yes, the $/$ was meant in a programming sense, but I've edited my answer. – blub Apr 06 '19 at 09:16
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$
- 3,461