
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Represent int32 as a Binary String in C#
To represent Int632as 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.
Int32 represents a 32-bit signed integer.
Firstly, set an Int64 variable −
int val = 30;
Now, convert it to a binary string by including 2 as the second parameter.
Convert.ToString(val, 2)
Example
using System; class Demo { static void Main() { int val = 30; Console.WriteLine("Integer: "+val); Console.Write("Binary String: "+Convert.ToString(val, 2)); } }
Output
Integer: 30 Binary String: 11110
Advertisements