Are there binary literals in Java?
问题 I want to declare my integer number by a binary literal. Is it possible in Java? 回答1: Starting with Java 7 you can represent integer numbers directly as binary numbers , using the form 0b (or 0B ) followed by one or more binary digits (0 or 1). For example, 0b101010 is the integer 42. Like octal and hex numbers, binary literals may represent negative numbers. If you do not have Java 7 use this: int val = Integer.parseInt("001101", 2); There are other ways to enter integer numbers: As decimal