Sunday, 11 August 2013

Unable to parse 64 bit binary numbers to long

Unable to parse 64 bit binary numbers to long

Given binary number in a string "0", I converted it to long to find its
Bitwise Not/Complement.
long number = Long.parseLong("0",2);
number = ~number;
System.out.println(Long.toBinaryString(number));
which prints
1111111111111111111111111111111111111111111111111111111111111111
i.e., 64 1's. But I'm unable to find complement of this.
Long.parseLong("111111111111111111111111111111111111111111111111111111111111111",2);
//fails
I get java.lang.NumberFormatException. What am I to do?

No comments:

Post a Comment