Home > Article > Backend Development > In C#, what is the octal equivalent of a decimal number?
To get the octal equivalent of a decimal number in C# −
First, for the decimal value, use a while loop and store the remainder in an array set for octal. Here we find their modulo 8 in the array.
After that, divide the number by 8 −
while (dec != 0) { oct[i] = dec % 8; dec = dec / 8; i++; }
Let’s look at the complete code. Here, our decimal number is 12 −
using System; namespace Demo { class Program { static void Main(string[] args) { int []oct = new int[50]; // decimal int dec = 12; int i = 0; while (dec != 0) { oct[i] = dec % 8; dec = dec / 8; i++; } for (int j = i - 1; j >= 0; j--) Console.Write(oct[j]); Console.ReadKey(); } } }
The above is the detailed content of In C#, what is the octal equivalent of a decimal number?. For more information, please follow other related articles on the PHP Chinese website!