5 ms·
Bit Twiddling Hacks
- dpapathanasiou 15y ago"Hacker's Delight" (http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201914654/ http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201...) is also a good source for these, as well as other techniques.
- windsurfer 15y agoAnyone else always spend a huge amount of time understanding someone elses code when their doing bit twiddling? It's just not intuitive to me, and I always abstract it away as much as possible.
- RandyHelzerman 15y agoHas anybody done any benchmarking lately to see if these hacks really save time? Seems like most of them rely on the assumption that the cpu has a barrel shifter and can do something like x>>23 in 1 clock cycle. I understand that some of the later x86 chips did not have a barrel shifter, so its not obvious to me that x>>23 would execute any faster than 1/(2 ^ 23) would. Does anybody know for sure?
- matrix3456 15y agoHow many people use this stuff in their daily job coding? Does this really matters and matters what?
- wladimir 15y agoI think this should be regarded as "recreational computer science". It's intriguing to see how much is possible with some bit twiddling. It also gives insight into how things are handled internally. But it's not for use in actual code, unless you're writing a video codec or other embedded system in which you want to shave off every cycle.