- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to convert a Decimal to Octal using C#?
To get the octal equivalent, use a while loop for the decimal value and store the remainder in the array set for octal. Here we have set the remainder by mod 8 in the array.
Then 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 18 −
using System; namespace Demo { class Program { static void Main(string[] args) { int []oct = new int[30]; // decimal int dec = 18; 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(); } } }
- Related Articles
- How to Convert Decimal to Octal?
- C++ Program to convert Decimal Numbers to Octal
- C# program to convert decimal to Octal number
- How to Convert Decimal to Binary, Octal, and Hexadecimal using Python?
- Java Program to convert Decimal to Octal
- Golang Program to convert Decimal to Octal
- Swift Program to convert Decimal to Octal
- Convert decimal integer to octal in Java
- C++ Program to convert Octal Number to Decimal and vice-versa
- Convert octal number to decimal number in Java
- Java program to convert decimal number to octal value
- Java program to convert float decimal to Octal number
- Java Program to convert decimal integer to octal number
- Java Program to convert octal number to decimal number
- Python program to convert float decimal to octal number

Advertisements