diff --git a/src/System/Random/Effect.hs b/src/System/Random/Effect.hs
--- a/src/System/Random/Effect.hs
+++ b/src/System/Random/Effect.hs
@@ -172,11 +172,13 @@
 
 -- | Returns the maximum set bit in an integer.
 maxBit :: Integer -> Int
-maxBit x =
-  let loop y !k
-        | y == 0    = k
-        | otherwise = loop (y `unsafeShiftR` 1) (k+1)
-   in loop x 0
+maxBit x
+  | x == 0    = 0
+  | otherwise =
+    let loop y !k
+          | y == 1    = k
+          | otherwise = loop (y `unsafeShiftR` 1) (k+1)
+     in loop x 0
 
 -- | Repeat a computation until it succeeds a test.
 loopUntil :: Monad m => (a -> Bool) -> m a -> m a
diff --git a/system-random-effect.cabal b/system-random-effect.cabal
--- a/system-random-effect.cabal
+++ b/system-random-effect.cabal
@@ -1,5 +1,5 @@
 name:                system-random-effect
-version:             0.1.1.0
+version:             0.1.2.0
 synopsis:            Random number generation for extensible effects.
 homepage:            https://github.com/wowus/system-random-effect
 license:             BSD3
