S
sameergn
Hi,
I have a small program which goes like this
public class Test
{
public static long x1 = 0xF000000000000001L;
public static void main(String args[])
{
System.out.println("x1 = " + x1);
long x2 = Long.parseLong("F000000000000001", 16);
System.out.println("x2 = " + x2);
}
}
Its output is
x1 = -1152921504606846975
Exception in thread "main" java.lang.NumberFormatException: For input
string: "F000000000000001"
at java.lang.NumberFormatException.forInputString(Unknown
Source)
at java.lang.Long.parseLong(Unknown Source)
at Test.main(Test.java:8)
My intention is to read a bit pattern having MSB set to 1, into a long
variable. The literal long value (x1) allows you to do that in source
file but parseLong() throws exception. Is it because parseLong()
tries to parse "signed" long (as per JavaDoc).
If so, what is a way to read such long value from a file?
I don't want to use DataInput.readLong() method as the value
must be read from a ASCII file.
Thanks,
Sameer
I have a small program which goes like this
public class Test
{
public static long x1 = 0xF000000000000001L;
public static void main(String args[])
{
System.out.println("x1 = " + x1);
long x2 = Long.parseLong("F000000000000001", 16);
System.out.println("x2 = " + x2);
}
}
Its output is
x1 = -1152921504606846975
Exception in thread "main" java.lang.NumberFormatException: For input
string: "F000000000000001"
at java.lang.NumberFormatException.forInputString(Unknown
Source)
at java.lang.Long.parseLong(Unknown Source)
at Test.main(Test.java:8)
My intention is to read a bit pattern having MSB set to 1, into a long
variable. The literal long value (x1) allows you to do that in source
file but parseLong() throws exception. Is it because parseLong()
tries to parse "signed" long (as per JavaDoc).
If so, what is a way to read such long value from a file?
I don't want to use DataInput.readLong() method as the value
must be read from a ASCII file.
Thanks,
Sameer