module Bits.Show where
import Data.Bits
import GHC.Exts
class FixedWidthIntegral
showFiniteBits :: (FiniteBits bits, IsString string) => bits -> string
showFiniteBits :: forall bits string.
(FiniteBits bits, IsString string) =>
bits -> string
showFiniteBits bits
x =
forall a. IsString a => String -> a
fromString
(
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Bool -> Char
showBit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Bits a => a -> Int -> Bool
testBit bits
x)
(forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Ord a => a -> a -> Bool
>= Int
0)
(
forall a. (a -> a) -> a -> [a]
iterate
(\Int
i -> Int
i forall a. Num a => a -> a -> a
- Int
1)
(forall b. FiniteBits b => b -> Int
finiteBitSize bits
x forall a. Num a => a -> a -> a
- Int
1)
)
)
)
showBit :: Bool -> Char
showBit :: Bool -> Char
showBit Bool
x = case Bool
x of
Bool
True -> Char
'1'
Bool
False -> Char
'0'