C# FAQ: How display int as a binary number, a string of 0s and 1s
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| CSharp-Online.NET:FAQs |
| edit |
[edit]
How display int as a binary number, a string of 0s and 1s?
The Convert class has an overload of the static ToString() method which accepts two ints and returns a string containing the specified number in the specified base.
For example, the following source code:
Console.WriteLine (Convert.ToString (128, 2) );
will result in the following output:
| Convert int to binary string example (program output) |
| 10000000 |