Reputation: 16226
Can someone give a clear explanation of what Binary Literal is? What is the difference between binary literals, hexadecimal and binary numbers, strings? What are they used for?
Upvotes: 0
Views: 197
Reputation: 180918
Literals: http://cpp.comsci.us/etymology/literals.html.
Literal constants (often referred to as literals or constants) are invariants whose values are implied by their representations
Just as a hexadecimal literal is a string of the form "0xABCD", a binary literal is a string of the form "0b11011011". They can be distinguished from each other by checking the first two characters.
http://docs.oracle.com/javase/7/docs/technotes/guides/language/binary-literals.html
Upvotes: 1
Reputation: 124790
Because sometimes it's easier to convey the intent of a value in binary. This applies to base 16 as well. They're all numbers when it comes down to it, but if I want to assign a flag with multiple bits set, something like this seems clearer than the alternative(s).
flags = 0b110101
Upvotes: 2
Reputation: 799490
They're used for expressing a number using bits.
0b0010010101001
Upvotes: 2