Search code examples
c#binarybitnotation

Binary notation for writing bits - C#


There are some notations to write numbers in C# that tell if what you wrote is float, double, integer and so on.

So I would like to write a binary number, how do I do that?

Say I have a byte:

byte Number = 10011000 //(8 bits)

How should I write it without having the trouble to know that 10011000 in binary = 152 in decimal?

P.S.: Parsing a string is completely out of question (I need performance)


Solution

  • as of c# 6 c# 7 you can use 0b prefix to get binary similar to the 0x for hex

    int x           = 0b1010000; //binary value of 80
    int seventyFive = 0b1001011; //binary value of 75
    

    give it a shot