How do I write a binary literal value into a variable?

0 votes
asked Jul 30, 2019 by (120 points)
I would like to be able to write binary values into variables. For example; int var = 10010101; Can anyone help me out?

Thank you!

2 Answers

0 votes
answered Aug 1, 2019 by (1,600 points)
Well you can't it would just take it as an integer hence won't work like you want but you could do it with hexadecimel try this int var = 0x95

in binary 0x95 is 10010101.

There may be workarounds you may find on web.
0 votes
answered Aug 8, 2019 by anonymous
You should write that as 0b10010101 (use prefix 0b when writing in base 2).
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...