14,423,526 members
Rate this:
See more:
i want to make a simple program to convert octal to decimal number only

What I have tried:

i have searched the internet but could not get answer to my question
Posted
Updated 2-Jul-19 20:41pm

Rate this:

Solution 1

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
Waseem6409 29-Jun-19 3:04am

i dont want everything i only need a formula of octal to decimal conversion,i can do everything else by myself
OriginalGriff 29-Jun-19 3:09am

Simple: convert octal to binary: that's trivial, each octal digit is three binary bits.
Then convert the binary to Hex: that's trivial, each hex digit is four bits from the binary.

So what part of this is giving you problems?
Waseem6409 29-Jun-19 3:34am

i did everything but the formula to convert i am stuck at like i did convert integer to binary,octal,hexadecimal by using builtin function but in this i have t o give code the formula i need help with that formula
OriginalGriff 29-Jun-19 3:44am

So what do you have as an input? Is it a string?
Rate this:

Solution 2

Octal to Decimal conversion:
I would take an example to show you this:
Octal number: 123
multiply the digit at hundredths place with 8^2
multiply the digit at tenths place with 8^1
and multiply the digit at zeroth place with 8^0
and add all of them 64*1+8*2+1*3 = 83.
```# Function to convert
# octal to decimal
def octalToDecimal(n):

num = n;
dec_value = 0;

# Initializing base value
# to 1, i.e 8^0
base = 1;

temp = num;
while (temp):

# Extracting last digit
last_digit = temp % 10;
temp = int(temp / 10);

# Multiplying last digit
# with appropriate base
# value and adding it
# to dec_value
dec_value += last_digit * base;

base = base * 8;

return dec_value; ```

I am also attaching the code but It uses functions. i would recommend you to refer it once you have tried it and also try this by simple loops or so. Later I would also try to share that approach.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Richard MacCutchan 155 OriginalGriff 100 F-ES Sitecore 100 CPallini 95 Wendelius 70
 OriginalGriff 4,313 Richard MacCutchan 1,566 Patrice T 899 Wendelius 890 phil.o 870

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100