VSDomotics

October 3rd, 2008, 10:25 AM

The LUA code

print(math.bxor(2147483648,2147483647))

should give 4294967295 as the right answer but I get -1.

How is this possible.

What I try to do is toggle a certain bit in a 4 byte word (32 bits)

So

mask= 10000000000000000000000000000000 (2147483648)

data= 01111111111111111111111111111111 (2147483647)

by XOR I should get

result= 11111111111111111111111111111111 (4294967295)

How is this possible? I think it perhaps has to do with a limitation of LUA (first bit used for sign somewhere?).

Is this intended behaviour or not? If so, how do I solve this in a simple way (toggling a certain bit in a 32 bits word)?

print(math.bxor(2147483648,2147483647))

should give 4294967295 as the right answer but I get -1.

How is this possible.

What I try to do is toggle a certain bit in a 4 byte word (32 bits)

So

mask= 10000000000000000000000000000000 (2147483648)

data= 01111111111111111111111111111111 (2147483647)

by XOR I should get

result= 11111111111111111111111111111111 (4294967295)

How is this possible? I think it perhaps has to do with a limitation of LUA (first bit used for sign somewhere?).

Is this intended behaviour or not? If so, how do I solve this in a simple way (toggling a certain bit in a 32 bits word)?