Home > other >  Python issue of exclusive or operation
Python issue of exclusive or operation

Time:10-01

Today in the use of Python's exclusive or operation, the results showed that the results and I don't expect as
 & gt;> A=255 
> B=1
> Print a ^ b
- 256

I expected result is a ^ b is equal to zero, because 255=0 XFF - 1=0 XFF,
Now don't know how to operation can I get the expected result,
O great god teach

CodePudding user response:

 In [3] : a=(1 & amp; 0 XFF) 

In [4] : b=(255 & amp; 0 XFF)

In [5] : a ^ b
The Out [5] : 0

In [6] :

CodePudding user response:

255=0 XFF.
- 1=0 XFF.
And 255-1 to a binary number is 0 XFF this logical?
Can only say 8-bit unsigned number is 255 and eight symbols - 1 the two's complement of the same
255 is the number of signed 011111111 extended to 32-bit signed number is 00 ff
1 is expanded to 111111111 the number of signed 32-bit signed number is FFFF

CodePudding user response:

The building Lord, python variable length is 32 bit or 64 bit? Why write only eight?
  • Related