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

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

    There are no binary literals in Java, but I suppose that you could do this (though I don't see the point):

    int a = Integer.parseInt("10101010", 2);
    

提交回复
热议问题