How to convert octal to decimal?

7k Views Asked by At

I tried to convert octal numbers to decimal numbers and I found the formula but I am expecting a different way.

My way is: the octal is $547$.

Formula: $(5*8^2)+(4*8^1)+(7*8^0)$

Answer: $355$

But I am expecting a different way.

Since I want to implement the concept to my java program and please kindly give any one update for this concept.

2

There are 2 best solutions below

3
On

Your way looks fine, except for your final result:

$$5 \cdot 8^2 + 4 \cdot 8^1 + 7 \cdot 8^0 = 5 \cdot 64 + 4 \cdot 8 + 7 \cdot 1 = 320+32+7=359$$

A second way is Horner's method (only for decimal-system) for using in calculation:

You also start with $359=5 \cdot 8^2 + 4 \cdot 8^1 + 7 \cdot 8^0$. Thats a sum of 3 products (left factor is your number, right factor is a multiple of 8). Re-arrange:

$$1\cdot 7 + 4 \cdot 8 + 5 \cdot 8^2=359$$

$$7+8\cdot (4+8\cdot 5)=359$$

Now you can use a calculator:

     Input              Output
        5                5
   [x]  8  [+]  4  [=]   44
   [x]  8  [+]  7  [=]   359

Hope this helps.

2
On

Another method working from left to right

$547_8$

Start with

$x = 0$ add the first digit $x = 5$

Now since there are more digits to follow multiply by 8 $x = 40$

add the next digit $x = 40+4 = 44$

Now since there are more digits to follow multiply by 8 $x = 352$

add the next digit $x = 352 + 7 = 359$

Now since there are no more digits we are done.