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

后端 未结 8 1170
[愿得一人]
[愿得一人] 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:15

    If you want to mess around with lots of binary you could define some constants:

    public static final int BIT_0 = 0x00000001;
    public static final int BIT_1 = 0x00000002;
    

    etc.

    or

    public static final int B_00000001 = 0x00000001;
    public static final int B_00000010 = 0x00000002;
    public static final int B_00000100 = 0x00000004;
    

提交回复
热议问题