[16941 views]

A number system with a base 10 is known as decimal number system. Hence, decimal numbers are denoted with a base 10.

This number system consists of 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Each digit in the decimal system has a position and every digit is ten times more significant than the previous digit.

For example: (461)_{10} , (370)_{10} , (890)_{10} , (400)_{10} , etc.

A number system with a base 8 is known as octal number system. Hence, octal numbers are denoted with a base 8. It consists of the values: 0,1,2,3,4,5,6,7.

For example: (462)_{8}, (27)_{8}, (500)_{8}, (3462)_{8}, etc.

We will start off by taking the decimal number to be converted as user input. We will convert the decimal number into octal by dividing the decimal number by 8 until we get 0. In each division, the remainder becomes the most significant bit of the octal number accordingly.

Hence, by the end, the first remainder is the least significant bit(LSB) and the last remainder is the most significant bit(MSB).

In this algorithm, we are starting a loop which runs until the decimal number becomes 0. The remainder is extracted with the help of modulus operator. After that, the remainder is multiplied by the place (starting from ones) in the octal number.

The place where the next remainder is to be inserted is tracked by the variable i, which is incremented after each division.
Once the number becomes 0, the division is stopped and the equivalent octal number is displayed.

Let us take a look at an example for better understanding:

Given decimal number: (461)_{10}461/8=57 and remainder = 5 57/8=7 and remainder = 1 7/8=0 and remainder = 7 So the octal number starts from MSD to LSD, i.e. 715 Therefore, (461)_{10}= (715)_{8}

- Algorithm and Flowchart to find if a Number is Even or Odd
- Algorithm and Flowchart to find whether a number is Prime Number or Not
- Algorithm and Flowchart for Armstrong Number
- Algorithm for Finding Factorial of a Number
- Algorithm and Flowchart to Calculate Fibonacci series up to n
- How to round a number to nearest integer using python
- Can we have DB table without a primary key?
- Why does everyone hate Java?
- How much JavaScript to learn for Web Development
- How to store password like sensitive information in application