Friday, January 24, 2020

Abhijeet Pal: Python Program to Convert Octal Number to Decimal and vice-versa

The octal numeral system, or oct for short, is the base-8 number system and uses the digits 0 to 7. The main characteristic of an Octal Numbering System is that there are only 8 distinct counting digits from 0 to 7 with each digit having a weight or value of just 8 starting from the least significant bit (LSB). In the decimal number system, each digit represents the different power of 10 making them base-10 number system. Problem definition Create a python program to convert an octal number into a decimal number. Algorithm for octal to decimal conversion Take an octal number as input. Multiply each digit of the octal number starting from the last with the powers of 8 respectively. Add all the multiplied digits. The total sum gives the decimal number. Program num = input("Enter an octal number :") OctalToDecimal(int(num)) def OctalToDecimal(num): decimal_value = 0 base = 1 while (num): last_digit = num % 10 num = int(num / 10) decimal_value += last_digit * base base = base * 8 print("The decimal value is :",decimal_value) Output Enter an octal number :24 The …

The post Python Program to Convert Octal Number to Decimal and vice-versa appeared first on Django Central.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...