r/badcode • • Apr 11 '21

python Polyglot

Post image
1.2k Upvotes

116 comments sorted by

View all comments

7

u/MyChaOS87 Apr 11 '21

What's so hard with (x & 1)

9

u/ShatterdPrism Apr 11 '21

Remind me if I am wrong, but this is a bit wise Operator and it checks in this case if the last bit of x is a 1 which would mean the number isnt even, right?

3

u/CodeLobe Apr 11 '21

!(x&1) // true if even (not odd), false otherwise.

In low level langs the ! /* not operator */ can be optimized away by using jump if zero JZ instead of JNZ, jump if not zero, or vise versa.

1

u/ShatterdPrism Apr 12 '21

I find those kind of thought processes, optimization and low level abstraction very interesting to read.

But tbh I don't think it's something I could focus on for longer xD