News for hackers. Stuff that matters.
Re:Low Level Bit Hacks You Absolutely Must Know by aurelian15 on Friday May 11, 2018 @12:23AM (#17044956)
Strangely enough, I often find my self impulsively writing (n & 1) to check for even/odd numbers. It just feels natural to me -- maybe because the first C programs I wrote were for µCs, where this kind of bit-twiddling tends to be used everywhere, and, correspondingly, people know what (n & 1) does. Sure enough, even on microcontrollers (n % 2) has no overhead compared to (n & 1) when optimisations are turned on.

It only ever caught my attention that writing (n & 1) is weird when some TAs looking at my code didn't understand what I was doing during my first college year.

Re:Low Level Bit Hacks You Absolutely Must Know by khedoros1 on Friday May 11, 2018 @01:12AM (#17045101)
It feels natural to me...but I also like writing emulators, so I've probably got more experience in common with µC devs than most other software developers do.
Re:Low Level Bit Hacks You Absolutely Must Know by thankthunk on Friday May 11, 2018 @06:31PM (#17051193)
It feels natural to anyone who understands binary numbers. Every odd number in binary will have the last bit as 1. Just like in the decimal system, every number that is a multiple of 10 will has the last digit as 0. If you want to see if a number is a multiple of ten, I guess you could do a mod 10 of the number and see if the remainder is 0. But if you understand the decimal system, you would just naturally check if the last digit is 0.