Skip to content

Instantly share code, notes, and snippets.

@msysyamamoto
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save msysyamamoto/28fd076cc7a2c576261f to your computer and use it in GitHub Desktop.

Select an option

Save msysyamamoto/28fd076cc7a2c576261f to your computer and use it in GitHub Desktop.
import Data.Bits
import Data.List
binStr :: Bits a => a -> String
binStr n = foldl' f "" $ take (bitSize n) [0..]
where
f str i
| testBit n i = '1' : str
| otherwise = '0' : str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment