K
Knute Johnson
I'm working on a project where I'm being given a string of 0s and 1s and
need to mask them against another string of the same. I thought I would
convert my string with Integer.parseInt("111",2) but I ran into a
problem. You can't parse out 32 bits to an int if the MSB is 1. It
throws a NumberFormatException. You can't parse -2147483648 in either
radix 2, 8 or 16. My data is of course LSB first so 1 would be
100000000000000000000000000000000 and I can't parse it. Anyway, I
thought it was interesting and wondered if anybody knows why this is so?
Thanks,
knute...
public class test {
public static void main(String[] args) {
// String str = "1111111111111111111111111111111";
// String str = "7fffffff";
// String str = "17777777777";
int n = Integer.parseInt(str,2);
System.out.println(n);
}
}
need to mask them against another string of the same. I thought I would
convert my string with Integer.parseInt("111",2) but I ran into a
problem. You can't parse out 32 bits to an int if the MSB is 1. It
throws a NumberFormatException. You can't parse -2147483648 in either
radix 2, 8 or 16. My data is of course LSB first so 1 would be
100000000000000000000000000000000 and I can't parse it. Anyway, I
thought it was interesting and wondered if anybody knows why this is so?
Thanks,
knute...
public class test {
public static void main(String[] args) {
// String str = "1111111111111111111111111111111";
// String str = "7fffffff";
// String str = "17777777777";
int n = Integer.parseInt(str,2);
System.out.println(n);
}
}