These Bit Twiddling Tricks Will Make Your Coworkers Hate You

In the embedded world, twiddling a few bits is expected behavior. Firmware is far enough down the stack that the author may care about the number of bits and bytes used, or needs to work with registers directly to make the machine dance. Usually these operations are confined to the typical shifting and masking but sometimes a problem calls for more exotic solutions. If you need to descend down these dark depths you invariably come across the classic Bit Twiddling Hacks collected by [Sean Eron Anderson]. Here be dragons.

Discussions of bit math are great opportunities to revisit Wikipedia’s superb illustrations

Bit Twiddling Hacks is exactly as described; a page full of snippets and suggestions for how to perform all manner of bit math in convenient or efficient ways. To our surprise upon reading the disclaimer at the top of the page, [Sean] observes that so many people have used the contents of the page that it’s effectively all been thoroughly tested. Considering how esoteric some of the snippets are we’d love to know how the darkest corners found use.

The page contains a variety of nifty tricks. Interview content like counting set bits makes an early appearance.  There’s more esoteric content like this trick for interleaving the bits in two u16’s into a single u32, or rounding up to the next power of two by casting floats. This author has only been forced to turn to Bit Twiddling Hacks on one occasion: to sign extend the output from an unfortunately designed sensor with unusual length registers.

Next time you need to perform an operation with bitmatch, check out Bit Twiddling Hacks. Have you ever needed it in production? How did you use it? We’d love to hear about it in the comments.

3D Print Your Very Own Mechanical Computer

Most Hackaday readers are familiar with computers from the 70s and 80s, but what about ones even older than that? The Digi Comp 1 was a commercially available computer from the 1960s that actually cost less than a modern-day microcontroller. The catch? It was mechanical rather than electrical. Thanks to retro-wizard [Mike Gardi], now anyone can build a replica of one.

Admittedly the Digi Comp 1 was more of a toy than a tool, but it was still a working computer. It contained three flip-flops (memory) and had a lever that acted as a clock, allowing the user to perform boolean operations and some addition and subtraction. Certainly not advanced, but interesting nonetheless. [Mike]’s version of the Digi Comp 1 has an extra bit when compared to the original and includes some other upgrades, but largely remains faithful to the original design.

If you want to print one of these on your own, [Mike] has made all of the files available on Thingiverse. He has also experimented with other mechanical computers as well, including the sequel Digi Comp 2. We’ve seen some recent interest in that mechanical computer lately as well.

Continue reading “3D Print Your Very Own Mechanical Computer”

Zippo Keeps Your Bits Safe

[Laura Kampf] found a new use for an old Zippo lighter by turning it into a carrier for her screwdriver bits. There are several multitools out there which can accept standard screwdriver bits. The problem is carrying those bits around. Leaving a few bits in your pocket is a recipe for pocket holes and missing bits.

[Laura’s] solution uses her old Zippo lighter. All she needs is the case, the lighter element itself can be saved for another project. A block of aluminum is cut and sanded down to a friction fit. Laura uses a band saw and bench sander for this. The aluminum block is then drilled out to fit four bits. Small neodymium magnets are taped into the holes with double-sided tape. These magnets retain the bits, ensuring none will fall out when the lighter is opened.

This is a great quick project and an excellent way to carry four bits. We’re curious if the second set of holes (and a shorter bar) could expand this carrier to 8 bits – 4 on top and 4 on the bottom. [Laura] noticed this too, but decided to keep the build simple with 4 bits.

We love Every Day Carry (EDC) projects like this – in fact, a few years back we had our own EDC contest featuring the Adafruit Trinket. Check out the awards announcement post for some awesome pocket projects!

Continue reading “Zippo Keeps Your Bits Safe”

Read Every Bit On A DVD

If you are curious about reading all the bits on a DVD, [tmbinc] has devised a hardware hack that uses a Pioneer DVD drive with leads soldered onto it and a Cypress FX2 microcontroller board to grab the flow of bits and push them over USB2.0. My favorite part of this tutorial is when you slow the spinning DVD down very slightly with your finger with a scope hooked up over what you believe to be the raw data stream from the disk. If the data rate slows when you physically slow down the disk, you probably are grabbing data from the correct pin. [tmbinc] even put together a software tool to process the resulting raw DVD data.