Page 1 of 1

Bit wise NOT behaviour

Posted: Tue Jun 12, 2018 7:19 am
by Blurryan

Code: Select all

x.b = %00000010
Debug RSet(Bin(x), 8, "0")
Debug "   "
Debug RSet(Bin(~x), 8, "0")
x shows me a value of "00000010"
but
~x shows me a value of "11111111"

Shouldn't ~x show a value of "11111101"?

Can someone please explain why this is happening?

Re: Bit wise NOT behaviour

Posted: Tue Jun 12, 2018 7:25 am
by Lord

Code: Select all

x.b = %00000010
Debug RSet(Bin(x), 8, "0")
Debug "   "
Debug RSet(Bin(~x&$FF), 8, "0")

Re: Bit wise NOT behaviour

Posted: Tue Jun 12, 2018 7:25 am
by firace
Try x.a rather than x.b :)

.b is a signed byte.

Re: Bit wise NOT behaviour

Posted: Tue Jun 12, 2018 7:27 am
by Blurryan
Problem resolves when I put length of Rset at 64 iso 8. It appears only the leftmost bits are being copied. So in a 32 bit m/c the length needs to be 32.

Re: Bit wise NOT behaviour

Posted: Tue Jun 12, 2018 7:29 am
by Blurryan
Thanks Lord and firace,
@Lord - Thanks yes tried it thanks.

@ firace - no the problem exists with both .a as well as .u

Rgds

Re: Bit wise NOT behaviour

Posted: Tue Jun 12, 2018 7:30 am
by wilbert
It's also possible to specify the type

Code: Select all

x.b = %00000010
Debug RSet(Bin(x, #PB_Byte), 8, "0")
Debug "   "
Debug RSet(Bin(~x, #PB_Byte), 8, "0")

Re: Bit wise NOT behaviour

Posted: Tue Jun 12, 2018 7:37 am
by Blurryan

Code: Select all

x.b = %00000010
Debug RSet(Bin(x), 64, "0")
Debug "   "
Debug RSet(Bin(~x), 64, "0")
The above gives me the following:
0000000000000000000000000000000000000000000000000000000000000010

1111111111111111111111111111111111111111111111111111111111111101

Re: Bit wise NOT behaviour

Posted: Tue Jun 12, 2018 7:39 am
by Blurryan
@Wilbert

Thanks. Understood. Need to tell the command what x is.