nave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 11 months agoI wishi.imgur.comimagemessage-square155fedilinkarrow-up1804arrow-down114
arrow-up1790arrow-down1imageI wishi.imgur.comnave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 11 months agomessage-square155fedilink
minus-squaremellejwz@lemmy.worldlinkfedilinkEnglisharrow-up2arrow-down1·11 months 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·11 months 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-up2·11 months agoModern compilers and interpreters are smart enough to figure out what you’re trying to do and automatically do that for you.
minus-squareziviz@lemmy.sdf.orglinkfedilinkEnglisharrow-up1·11 months agoHuh… That makes sense. Til. Ran some tests but speed is pretty similar. Only 4% faster using bitmath or 300 milliseconds difference after 10mil runs.
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.
Huh… That makes sense. Til. Ran some tests but speed is pretty similar. Only 4% faster using bitmath or 300 milliseconds difference after 10mil runs.