Skip to content

Instantly share code, notes, and snippets.

@bradparker bradparker/Bits.hs
Created Jul 8, 2019

Embed
What would you like to do?
Bits
import Control.Monad.State
import Data.Traversable
import Data.Tuple
toByteBits :: Integral n => n -> [n]
toByteBits =
evalState (for [1..8] (\_ -> state (\s -> swap (divMod s 2))))
main = do
print $ toByteBits 1
print $ toByteBits 2
print $ toByteBits 3
print $ toByteBits 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.