Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 532
Daniel Möller Avatar asked Nov 29 '22 07:11

Daniel Möller


1 Answers

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

like image 105
Kieran Avatar answered Dec 04 '22 22:12

Kieran