Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

+1 vote
asked Jul 30, 2019 by Jon (130 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 Loki (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.
...