nave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 1 year agoI wishi.imgur.comimagemessage-square90fedilinkarrow-up1507arrow-down14
arrow-up1503arrow-down1imageI wishi.imgur.comnave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 1 year agomessage-square90fedilink
minus-squarePulsar@lemmy.worldlinkfedilinkarrow-up5·1 year agohttps://realpython.com/python-modulo-operator/#how-to-check-if-a-number-is-even-or-odd I just wonder why module is the wrong solution.
minus-squaremellejwz@lemmy.worldlinkfedilinkEnglisharrow-up2arrow-down1·1 year agoNot neccessarily wrong, but you could also check the first bit. If it’s 1 the number is uneven, if it’s 0 the number is even. That seems to be more efficient.
minus-squaredukk@programming.devlinkfedilinkarrow-up3·1 year agoThat’s what I was thinking too… Although, I wouldn’t be surprised if most languages convert modulo 2 to this automatically.
minus-squareherrvogel@lemmy.worldlinkfedilinkarrow-up1·1 year agoModern compilers and interpreters are smart enough to figure out what you’re trying to do and automatically do that for you.
https://realpython.com/python-modulo-operator/#how-to-check-if-a-number-is-even-or-odd
I just wonder why module is the wrong solution.
Not neccessarily wrong, but you could also check the first bit. If it’s 1 the number is uneven, if it’s 0 the number is even. That seems to be more efficient.
That’s what I was thinking too… Although, I wouldn’t be surprised if most languages convert modulo 2 to this automatically.
Modern compilers and interpreters are smart enough to figure out what you’re trying to do and automatically do that for you.