S
Sébastien de Mapias
Hi,
I'd like to make a numeric key value from a String I receive.
I've tried these 2 ways with a different result:
String s3 = "ABCD";
char s2c3[] = s3.toCharArray();
long l2 = 0;
BigInteger bi = new BigInteger("0");
for (int i=0; i<s2c3.length; i++) {
Integer j = Character.getNumericValue(s2c3);
bi = (bi.shiftLeft(8)).add(new BigInteger(j.toString()));
}
System.out.println("ABCD vaut "+bi.longValue());
for (int i=0; i<s2c3.length; i++) {
l2 = (l2<<8) + (s2c3&0xff);
}
System.out.println("ABCD vaut "+l2);
I get the following output:
ABCD vaut 168496141
ABCD vaut 1094861636
Why are the results different ? What am I missing here ?
Thanks.
Regards,
SR
I'd like to make a numeric key value from a String I receive.
I've tried these 2 ways with a different result:
String s3 = "ABCD";
char s2c3[] = s3.toCharArray();
long l2 = 0;
BigInteger bi = new BigInteger("0");
for (int i=0; i<s2c3.length; i++) {
Integer j = Character.getNumericValue(s2c3);
bi = (bi.shiftLeft(8)).add(new BigInteger(j.toString()));
}
System.out.println("ABCD vaut "+bi.longValue());
for (int i=0; i<s2c3.length; i++) {
l2 = (l2<<8) + (s2c3&0xff);
}
System.out.println("ABCD vaut "+l2);
I get the following output:
ABCD vaut 168496141
ABCD vaut 1094861636
Why are the results different ? What am I missing here ?
Thanks.
Regards,
SR