I want to declare my integer number by a binary literal. Is it possible in Java?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Starting with Java 7 you can represent integer numbers directly as binary numbers, using the form
0b(or0B) followed by one or more binary digits (0 or 1). For example,0b101010is the integer 42. Like octal and hex numbers, binary literals may represent negative numbers.If you do not have Java 7 use this:
There are other ways to enter integer numbers:
As decimal numbers such as
1995,51966. Negative decimal numbers such as-42are actually expressions consisting of the integer literal with the unary negation operation.As octal numbers, using a leading 0 (zero) digit and one or more additional octal digits (digits between 0 and 7), such as 077. Octal numbers may evaluate to negative numbers; for example
037777777770is actually the decimal value -8.As hexadecimal numbers, using the form 0x (or 0X) followed by one or more hexadecimal digits (digits from 0 to 9, a to f or A to F). For example,
0xCAFEBABELis the long integer 3405691582. Like octal numbers, hexadecimal literals may represent negative numbers.More details can be found in this Wikibook.