-10

Everybody knows that if you declare a 8 bit value, you can do something like

int a = B10001110; 

like that vut I dont know how to declare it in 16 bit, I did something like

int b = B1000000100001111; 

but this gives me error. Is there something I can do about this? I want this 16 bit format declaration.

alk
  • 69,737
  • 10
  • 105
  • 255

2 Answers2

6

C++14 allows you to use a binary literal of the form

int b = 0b1000000100001111;

The type of the literal follows the same rules as for hexadecimal literals. This is not standard C, although some C compilers allow it as an extension.

Your B notation is neither standard C nor standard C++.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
2

Perhaps you could use this?

strtol("1000000100001111", NULL, 2);

At least it's standard C.

meaning-matters
  • 21,929
  • 10
  • 82
  • 142