+-- | 'countBits' @av@ returns the number of bits that is required to
+-- represent @av@.
+countBits ∷ Word32 → Word8
+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
+