HN Hall of Fame Weekly email

Bit Twiddling Hacks

graphics.stanford.edu Reference Documentation & references Computer science Candidate
Screenshot of graphics.stanford.edu captured 2026-07-20
Page preview · captured 2026-07-20

Resurfaced independently across 17 calendar years, with breakout response in 3 of them.

submissions
46
submitters
45
observed span
2007–2026
peak thread · 33 comments
143 pts
latest 20+ return · 2024-08-23
92 pts

Submission timeline

2007–2026

One slot for every year since HN launched. Height is that year's peak points; orange marks a 100+ point or 50+ comment breakout. Select a bar to open its strongest thread.

First comments on top threads

HN comment order

This kind of hacks is a major part of how we made Scala.js' 64-bit integers fast (the fastest known implementation of 64-bit integers on JavaScript). See [1] for the implementation, and [2] at section 4.4 for the long explanation with benchmarks and the other tricks we use. [1] https://github.com/scala-js/scala-js/blob/v1.3.1/linker-priv... [2] https://lampwww.epfl.ch/~doeraene/thesis/doeraene-thesis-201...

sjrd·143-point thread·

My favourite bit of bit twiddling doesn't seem to appear here - how to enumerate all the subsets of bits set. Like so many bit-twiddling hacks, I first saw this in chess engines: https://www.chessprogramming.org/Traversing_Subsets_of_a_Set

thom·136-point thread·

Just a fair warning as someone who has made extensive use of this page in the past: many of these hacks often end up slower these days on modern CPUs than naive approaches. Especially the no-branch and no-multiply math ops. As always, be sure to performance test your code if you're getting into obfuscating your algorithms to boost speeds. That said, there are still plenty of real gems in there. And on that note, here's one of my favorite bit-twiddling…

byuu·127-point thread·

It's worth noting that modern x86 CPUs have specialized extensions for bit manipulation. Furthermore C23 added stdbit.h that has some operations for bit manipulation https://en.wikipedia.org/wiki/X86_Bit_manipulation_instructi... https://thephd.dev/_vendor/future_cxx/papers/C%20-%20Modern%...

zokier·92-point thread·

The first top-level comment from each of the four biggest threads, in HN’s own order. Excerpts are shortened; open a comment for full context.

Breakout years
3

100+ points or 50+ comments

Total points
922

reference only — not used in Hall rules or ranking

Total comments
167

reference only — not used in Hall rules or ranking

Every submission

DateTitle as submittedByPointsComments
2007-12-05Bit Twiddling Hackshhm183
2009-03-12Bit Twiddling Hacks mroman496
2010-07-16Bit Twiddling Hacksdsc30
2011-03-20Bit Twiddling Hacksnathanh22
2011-05-21Bit Twiddling Hackswglb6014
2011-06-07Bit Twiddling Hackscoliveira294
2012-01-11Bit Twiddling Hacksahalan5017
2012-02-12Fastest way to count set bits.snihalani20
2012-05-28Bit Twiddling Hacks pagejim30
2012-10-05My goto source for bit hacks.sinzone40
2012-12-26Bit Twiddling Hacksnaftaliharris50
2013-02-20Bit Twiddling Hackspagejim20
2013-12-19Bit Twiddling Hacksbratfarrar60
2014-12-15Bit Twiddling Hacks (2005)thealphanerd506
2015-01-30Bit Twiddling Hacksaburan2820
2015-02-15Bit Twiddling Hacksallending20
2015-05-04Counting bits set: Brian Kernighan's wayruuki20
2015-05-13Bit twiddling hacks for programmerstjomk30
2015-06-23Bit Twiddling Hacksjoemanaco20
2015-08-22Bit Twiddling Hacks – Sean Eron Andersons_dev20
2016-03-21Bit twiddling hacks (2005)lgessler21
2016-07-03Bit Twiddling Hacks (2005)First breakoute-sushi12724
2017-10-06Bit Twiddling Hacksrelyio10
2017-10-07Bit Twiddling Hacksgeospeck10
2017-10-09Bithacksdlsym71
2017-11-07Bit Twiddling Hackspantuza30
2017-11-19Bit Twiddling Hacks (2005)kercker663
2018-03-27Bit Twiddling Hacksraviqqe4210
2018-07-27Bit Twiddling HacksDarkManZero10
2019-05-01Bit Twiddling Hacksjakobdabo40
2019-10-24Bit Twiddling Hacksingve30
2020-01-17Bit Twiddling Hacksslowhand0920
2020-03-31Bit Twiddling Hackssimonpure20
2020-12-04Bit Twiddling HacksBest threadCieplak14333
2022-03-16Bithacksgalkk10
2022-04-23Bit Twiddling Hacksgballan40
2022-10-11Bit Twiddling Hacks (2005)cardamomo20
2022-10-23Bit Twiddling Hacks (2005)pabs320
2022-10-25Bit Twiddling Hacks (2005)memorable13625
2024-02-22Bit Twiddling Hacksprvt30
2024-04-20Bit Twiddling Hacksyudga31
2024-04-20Bit Twiddling Hacksmakapuf141
2024-05-29Bit Twiddling Hacksjihadjihad10
2024-08-23Bit Twiddling Hacks (2009)Latest 20+ point returnelpocko9225
2025-12-11Bit Twiddling Hacksgurjeet21
2026-05-26Bit Twiddling Hackstosh30