![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the octal equivalent of a decimal number in C#?
To get the octal equivalent of a decimal in C# −
Firstly, for the decimal value use a while loop and store the remainder in the array set for octal. Here we found the mod 8 of them in the array.
After that, divide the number by 8 −
while (dec != 0) { oct[i] = dec % 8; dec = dec / 8; i++; }
Let us see the complete code. Here, our decimal number is 12 −
Example
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(); } } }
Advertisements