← ALL NOTES
Math

231. Power of Two

Is n a power of two? In binary, a power of two is a single 1 bit followed by zeros — 1, 10, 100, 1000 — so the question is really "does n have exactly one bit set?" And there's a one-instruction way…

Loading…