Represent Int32 as a Octal String in C#

CsharpProgrammingServer Side Programming

To represent Int32 as a Octal string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 8 for Octal.

Int32 represents a 32-bit signed integer.

Firstly, set an Int32 variable.

int val = 99;

Now, convert it to octal string by including 8 as the second parameter.

Convert.ToString(val, 8)


 Live Demo

using System;
class Demo {
   static void Main() {
      int val = 99;
      Console.WriteLine("Integer: "+val);
      Console.Write("Octal String: "+Convert.ToString(val, 8));


Integer: 99
Octal String: 143
Updated on 23-Jun-2020 08:23:40