+-- | 'countBits' @av@ returns the number of bits that is required to
+-- represent @av@.
+countBits ∷ Num a ⇒ Word32 → a
+{-# INLINEABLE countBits #-}
+countBits av
+ | av < (1 `shiftL` 8) = getNBits (fromIntegral av)
+ | av < (1 `shiftL` 16) = getNBits (fromIntegral (av `shiftR` 8)) + 8
+ | av < (1 `shiftL` 24) = getNBits (fromIntegral (av `shiftR` 16)) + 16
+ | otherwise = getNBits (fromIntegral (av `shiftR` 24)) + 24
+
+-- | Return 0 for 'False' and 1 for 'True'.
+b2n ∷ Num a ⇒ Bool → a
+{-# INLINE b2n #-}
+b2n True = 1
+b2n False = 0
+
+getNBits ∷ Num a ⇒ Word8 → a
+{-# INLINE getNBits #-}
+getNBits = fromIntegral ∘ UV.unsafeIndex nbitsTable ∘ fromIntegral