My post was incorrect. Xojo’s default is bit-fill for Int32 unless you specify the number of bits, but zero-fill for Int64 in all cases. With Int32 and In64 variables assigned the value -8000, these are the results of the various operations:
I’ve compared the result of this java code and xojo using bitwise.ShiftRight and got the same result. However, I’ll check the issue.
[code]import java.util.Arrays;
public class HelloWorld {
public static void main(String[] args) {
int k = 5144;
int m = 39738973;
int key = 5734;
int n = m - key + 1815549477 ^ 0x6C371625;
int[] data = new int[4];
data[0] = n & 0xFF;
data[1] = n >>> 8 & 0xFF;
data[2] = n >>> 16 & 0xFF;
data[3] = n >>> 24 & 0xFF;
System.out.println(Arrays.toString(data));
}
Pretty sure it’s not
Will double check with Joe as he’s out sick today
Pretty sure what s going on is
For a 32 bit value doing a shift right
32 bit value with MSB set gets assigned to 64 bit value for the framework (it IS documented as taking a 64 bit value)
step 1 causes the sign bit to be extended up through the upper 32 bits of the 64 bit value (this is basically required to make sure that a negative 32 bit value remains the same negative 64 bit value)
the shift is done (note MSB of the 32 bit value will whatever the sign bit WAS set to shifted in BUT the MSB of the 64 bit value will get a 0)
the 64 bit values is return and truncated to 32 bits
the MSB of the 32 bit value still has the sign bit set to whatever it was before (if it was 0 its still 0 if it was 1 its still 1)
For a 64 bit value this behaves differently because there is NO sign extension or truncation going on
So the shift right rolls a 0 into the MSB of the 64 bit value
Too many underlying niggly details but that’s what I suspect is going on - and basically “not a bug” IMHO
When you specify the number of bits as “32” it now treats things as 32 bit instead of 64 bit so the MSB of the 32 bit value gets a 0 rolled into the MSB on a shift