1

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.

user
  • 551
  • 1
    In Java Integer.parseInt(oct,8) will convert the number oct into decimal. See http://stackoverflow.com/questions/13147109/decimal-to-octal-conversion – Belgi Jan 10 '14 at 09:43
  • sure, i know this method will do.. but i have to do through calculatio.. – user120362 Jan 10 '14 at 09:45

4 Answers4

2

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.

ulead86
  • 3,381
2

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.

Warren Hill
  • 3,092
0

There are multiple ways that are both direct and indirect conversions to base $10$. I will use power of $2$ bases to illustrate my point.

$x \cdot 8^y + z \cdot 8^{y-1} +\dotsb$ is the easiest of the direct ways: $8\to 10$

The second easiest way in my opinion is this route: $8\to 2\to 10$

There are lots (specifically $2!-x$ for ones with $2$ of these, $3!-y$ for ones with $3$ of these, and $4!-z$ for ones with all $4$ of these) of other indirect routes but the most common ones you will see are ones with base $8$ and/or base $16$ and/or base $4$ and/or base $2$.

$x$, $y$, and $z$ here in the factorial expressions are representing the number of arrangements that don't start with base $8$.

egreg
  • 238,574
Caters
  • 337
0

Note 8 = 2^3. so 8^i = 2^(3i). So if your number is $a_n a_{n-1} \ldots a_1 a_0$, you can write it as $a_0 2^0 + a_1 2^3 + a_2 2^6 + \ldots + a_n 2^n = (a_0 << 0) | (a_1<<3) | \ldots | (a_n << 3n)$ where $<<$ is a bitshift and $|$ is bitwise or, where $a_i$ is represented in the binary ( so $0 =0,1=1,2=10,3=11,4=100,5=101,6=110,7=111$). Then, you have built the binary representation using bitwise operations, which yoru regular print routine will print out in decimal.

Batman
  • 19,390