Given an binary string as input, we need to write a program to convert the binary string into equivalent integer. To convert an binary string to integer, we have to use Convert.ToInt32(String, Base/Int32) function to convert the values. The base of the binary is 2.
Syntax:
Convert.ToInt32(String, Base/Int32);
Examples:
Input : 1010101010101010
Output : 43690
Input : 1100011000
111100001111
11001100110011001100
Output : 792
3855
838860
Program 1:
csharp
// C# program to convert array // of binary string to an integer using System; using System.Text; class GFG { static void Main(string[] args) { // binary number as string string bin_strng = "1010101010101010"; int number = 0; // converting to integer number = Convert.ToInt32(bin_strng, 2); // to print the value Console.WriteLine("Number value of binary \"{0}\" is = {1}", bin_strng, number); } } |
chevron_right
filter_none
Output:
Number value of binary "1010101010101010" is = 43690
Program 2:
C#
// C# program to convert array // of binary string to an integer using System; using System.Text; namespace geeks { class GFG { static void Main(string[] args) { // binary number as string string bin_strng = "1100011000"; int number = 0; // converting to integer number = Convert.ToInt32(bin_strng, 2); // to print the value Console.WriteLine("Number value of binary \"{0}\" is = {1}", bin_strng, number); bin_strng = "111100001111"; // converting to integer number = Convert.ToInt32(bin_strng, 2); // to print the value Console.WriteLine("Number value of binary \"{0}\" is = {1}", bin_strng, number); bin_strng = "11001100110011001100"; // converting to integer number = Convert.ToInt32(bin_strng, 2); // to print the value Console.WriteLine("Number value of binary \"{0}\" is = {1}", bin_strng, number); // hit ENTER to exit Console.ReadLine(); } } } |
chevron_right
filter_none
Output:
Number value of binary "1100011000" is = 792 Number value of binary "111100001111" is = 3855 Number value of binary "11001100110011001100" is = 838860
Recommended Posts:
- C# Program to Convert the Octal String to an Integer Number
- Different ways to convert String to Integer in C#
- Different Ways to Convert Double to Integer in C#
- How to Convert Integer Array to List in C#?
- C# Program for Converting Hexadecimal String to Integer
- C# Program for Count set bits in an integer
- Program to convert Byte array to IP Address
- C# | Convert.ToSingle(String, IFormatProvider) Method
- C# | Convert.ToString(String, IFormatProvider) Method
- C# | Convert.FromBase64String(String) Method
- C# | Convert.ToBoolean(String, IFormatProvider) Method
- C# | Convert.ToByte(String, IFormatProvider) Method
- C# | Convert.ToDateTime(String, IFormatProvider) Method
- C# | Convert.ToChar(String, IFormatProvider) Method
- C# | Convert.ToDecimal(String, IFormatProvider) Method
- C# | Convert.ToInt32(String, IFormatProvider) Method
- C# | Convert.ToDouble(String, IFormatProvider) Method
- C# | Convert.ToInt16(String, IFormatProvider) Method
- C# | Convert.ToSByte(String, IFormatProvider) Method
- C# | Convert.ToInt64(String, IFormatProvider) Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

