0

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?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Vincent
  • 16,086
  • 18
  • 67
  • 73
  • 1
    Literals: http://cpp.comsci.us/etymology/literals.html. A binary literal would most likely be a string of the form "0b11011011". – Robert Harvey Apr 04 '12 at 23:32

3 Answers3

2

They're used for expressing a number using bits.

0b0010010101001
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2

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
Ed S.
  • 122,712
  • 22
  • 185
  • 265
1

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

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501