Bit wise NOT behaviour

Just starting out? Need help? Post your questions and find answers here.
Blurryan
User
User
Posts: 32
Joined: Sat Oct 13, 2007 2:08 pm
Location: Kazakhstan

Bit wise NOT behaviour

Post 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?
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: Bit wise NOT behaviour

Post by Lord »

Code: Select all

x.b = %00000010
Debug RSet(Bin(x), 8, "0")
Debug "   "
Debug RSet(Bin(~x&$FF), 8, "0")
Image
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Bit wise NOT behaviour

Post by firace »

Try x.a rather than x.b :)

.b is a signed byte.
Blurryan
User
User
Posts: 32
Joined: Sat Oct 13, 2007 2:08 pm
Location: Kazakhstan

Re: Bit wise NOT behaviour

Post 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.
Blurryan
User
User
Posts: 32
Joined: Sat Oct 13, 2007 2:08 pm
Location: Kazakhstan

Re: Bit wise NOT behaviour

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Bit wise NOT behaviour

Post 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")
Windows (x64)
Raspberry Pi OS (Arm64)
Blurryan
User
User
Posts: 32
Joined: Sat Oct 13, 2007 2:08 pm
Location: Kazakhstan

Re: Bit wise NOT behaviour

Post 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
Blurryan
User
User
Posts: 32
Joined: Sat Oct 13, 2007 2:08 pm
Location: Kazakhstan

Re: Bit wise NOT behaviour

Post by Blurryan »

@Wilbert

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