In Java, can I define an integer constant in binary format?

后端 未结 8 1106
[愿得一人]
[愿得一人] 2020-11-27 14:50

Similar to how you can define an integer constant in hexadecimal or octal, can I do it in binary?

I admit this is a really easy (and stupid) question. My google sea

8条回答
  •  遥遥无期
    2020-11-27 15:38

    Search for "Java literals syntax" on Google and you come up with some entries.

    There is an octal syntax (prefix your number with 0), decimal syntax and hexadecimal syntax with a "0x" prefix. But no syntax for binary notation.

    Some examples:

    int i = 0xcafe ; // hexadecimal case
    int j = 045 ;    // octal case
    int l = 42 ;     // decimal case
    

提交回复
热议问题