Decimal to Octal Conversion
You are given a decimal number as input. You need to convert this number into its equivalent in the octal number system. The octal number system is the number system with a base value = 8.
A number system with base value = n means that all numbers, when written in this number system, will be represented with only digits from 0 to n-1. For example, the Binary number system has a base value = 2, so any number, when written in the binary system, will be represented using the digits 0 and 1 only.
Note:
The binary number system requires 2 digits (0-1), the Ternary number system requires 3 digits (0-2), the Octal number system requires 8 digits (0-7), and the decimal number system requires 10 digits (0-9) to represent any numeric value.
Input Format:
The first line contains a single integer 'T' representing the number of test cases.
The first and the only line of each test case will contain an integer 'X', denoting the decimal number to be converted to the octal format.
Output Format:
For each test case, print a single line containing an integer denoting the octal value of 'X'.
The output of each test case will be printed in a separate line.
Note:
You don't have to print anything. it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10 ^ 5
0 <= X <= 10 ^ 9
Time Limit: 1 sec.
CodingNinjas
author
2y
Step 1 : To convert decimal to binary, I used a while loop running till number > 0 wherein I divided number by 2 and stored the remainder at the beginning of an output string (initialized as empty).
St...read more
CodingNinjas
author
2y
Maths
- A necessary observation for octal numbers is that every digit will lie in the range 0 - 7.
- Create a variable sol to store the final octal representation of X and initialise sol to 0.
- So, to convert...read more
Help your peers!
Add answer anonymously...
Top Societe Generale Global Solution Centre Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Societe Generale Global Solution Centre Software Engineer
>
Societe Generale Global Solution Centre Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app