A Bit of Power
by in CodeSOD on 2021-02-25Powers of two are second nature to a lot of programmers. They're nearly inescapable.
Equally inescapable are programmers finding new ways to do simple things wrong. Take Sander's co-worker, who needed to figure out, given a number of bits, what's the largest possible value you could store in that number of bits. You or I might reach for our language's pow
function, but boy, in C++, that might mean you need to add an include file, and that sounds hard, so let's do this instead: