[20889 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}

- Java IDE Online
- Python IDE Online
- JSON Formatter/Minifier Online
- Case Converter
- Reverse String
- HTML Encoder
- HTML Decoder
- URL Encoder
- URL Decoder
- Decimal To Binary
- Binary To Decimal
- Decimal To Octal
- Binary To Octal
- Decimal To Hexadecimal
- Hexadecimal To Decimal
- Hexadecimal To Binary
- Octal To Decimal
- Octal to Hexadecimal
- Octal to Binary
- Calculate String Length
- Remove Spaces
- Remove Line Breaks
- Remove Empty Lines
- Remove Duplicate Lines
- Word Counter
- Replace Space with hyphen
- Check Armstrong number
- Text to URL