Posted By:
Alan_Honczar
Posted On:
Thursday, July 3, 2003 08:08 AM
Hi, due a key generation stuff, I experienced the following, and I'd like to know why. I read that a byte was in the range 0-127. If I write char mychar = 0x7C; I can compile. If I write char mychar = 0xFC; I can't compile. I saw that bytes first bit can't be true... But in run time a byte can accept values like 0xFC. as shown in byte a = 0x7F; a < <= 2; System.out.println(" 0x"+Integer.toHexString(((int)a)&0x000000FF)); Appending that code I found something strange. I used right shift and right unsigned shift and found the same result (signed). a >>= 2; //or a >>>
More>>
Hi, due a key generation stuff, I experienced the following, and I'd like to know why.
I read that a byte was in the range 0-127.
If I write char mychar = 0x7C; I can compile.
If I write char mychar = 0xFC; I can't compile.
I saw that bytes first bit can't be true...
But in run time a byte can accept values like 0xFC.
as shown in
byte a = 0x7F;
a
<
<= 2;
System.out.println(" 0x"+Integer.toHexString(((int)a)&0x000000FF));
Appending that code I found something strange.
I used right shift and right unsigned shift and found the
same result (signed).
a >>= 2; //or a >>>= 2; gives me the same.
System.out.println(" 0x"+Integer.toHexString(((int)a)&0x000000FF));
the only way to unsign a shift of two was anding it.
a &= 0x3F;//to zero the first 2 bits (as I shifted of 2)
I could not find out a explanation to this behavior.
TIA,
Alan Honczar
<<Less