The intro sentence, "At a fundamental level, a programmer needs to manipulate bits," gave me a strange moment of mental dissonance.<p>It just highlights to me how the job of "programmer" can be many things, depending on your domain. One could argue that a goal of programming is to build higher abstractions so you <i>don't</i> need to manipulate bits in order to express yourself.<p>But that aside, I enjoy this stuff, so here are some links for others interested:<p>* A neat SO post about implementing "popcount" using SWAR trickery: <a href="https://stackoverflow.com/questions/109023/count-the-number-of-set-bits-in-a-32-bit-integer/109025#109025" rel="nofollow noreferrer">https://stackoverflow.com/questions/109023/count-the-number-...</a><p>* Good collections of bit hacks:<p>** <a href="https://graphics.stanford.edu/~seander/bithacks.html" rel="nofollow noreferrer">https://graphics.stanford.edu/~seander/bithacks.html</a> (also mentioned in the article's comments)<p>** <a href="http://aggregate.org/MAGIC/" rel="nofollow noreferrer">http://aggregate.org/MAGIC/</a>
Go doesn't differ a ton from other programming languages but there are definitely a couple of things. I think when it comes to bit manipulation, my favorite detail about Go is the built-in AND NOT operator, which also has a corresponding compound assignment operator. It's mentioned in here, but I think it's worth calling out: not all languages have it, but it's a good addition.
Interesting! Only yesterday I had to get back into the bits (actually treating integera as bits, using shift operations and masks and bitwise-and), for the purpose of implementing base64 encoding. Good to know how to do this kind of stuff.
Bit tweaking is always fun. I have the need to implement a long bit array spanning multiple words recently and it gets surprisingly non-trivial quickly, especially dealing with subranges or searching for the next 0 or 1 bit from a starting position. But it's still loads of fun.
Implementing a bitset[0] in Go is a fun exercise if this article interested you.<p>[0] <a href="https://en.wikipedia.org/wiki/Bit_array" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Bit_array</a>