Questions

How do you Convert from Decimal to Octal?

We can convert from octal to decimal by following these steps:

                    

def octalToDecimal(num):
 
    number = n
    dec_value = 0
 
    # Initializing base value
    # to 1, i.e 8^0
    base = 1
 
    temp = number
    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
 
# Driver Code
number = 67
print(octalToDecimal(number))

This code gives the output in octal number: 55

Related Questions

Related Topics

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.