views:

585

answers:

2

I am really stumped on this one. In C# there is a hexadecimal constants representation format as below :

int a = 0xAF2323F5;

is there a binary constants representation format?

+4  A: 

Nope, no binary literals in C#. You can of course parse a string in binary format using Convert.ToInt32, but I don't think that would be a great solution.

int bin = Convert.ToInt32( "1010", 2 );
Ed Swangren
I'll leave the question open for a few hours but this being the first answer, if it proves true, it will be chosen as the official answer. Thank you.
Andrei Rinea
It is true... might as well accept now.
Marc Gravell
Accepting now..
Andrei Rinea
+2  A: 

You could use an extension method:

public static int ToBinary(this string binary)
{
    return Convert.ToInt32( binary, 2 );
}

However, whether this is wise I'll leave up to you (given the fact it will operate on any string).

Dan Diplo