on-internet
← Community

How to overcome Python's two complement notation?

Stack Overflow ·

How to overcome Python's two complement's notation and get 0b011111111111111 in the last result? Can it be done mathematically? Just can't figure out for hours already... output = 0xFFFF for i in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15): a = 1 << i print(bin(output^a)) Result: 0b1111111111111110 ✅ 0b1111111111111101 ✅ 0b1111111111111011 ✅ 0b1111111111110111 ✅ 0b1111111111101111 ✅ 0b1111111111011111 ✅ 0b1111111110111111 ✅ 0b1111111101111111 ✅ 0b1111111011111111 ✅ 0b1111110111111111 ✅ 0b1111101111111111 ✅ 0b1111011111111111 ✅ 0b1110111111111111 ✅ 0b1101111111111111 ✅ 0b1011111111111111 ✅ 0b111111

Comments

Sign in or sign up to comment and upvote.

No comments yet.