Represent Int64 as a Binary string in C#

ProgrammingServer Side ProgrammingCsharp

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

Int64 represents a 64-bit signed integer.

Firstly, set an Int64 variable.

long val = 753458;

Now, convert it to binary string by including 2 as the second parameter.

Convert.ToString(val, 2)

Example

 Live Demo

using System;
class Demo {
   static void Main() {
      long val = 753458;
      Console.WriteLine("Long: "+val);
      Console.Write("Binary String: "+Convert.ToString(val, 2));
   }
}

Output

Long: 753458
Binary String: 10110111111100110010
raja
Published on 11-Sep-2018 09:16:40
Advertisements