@@ -29,15 +29,20 @@ module Truncate.Internal where
2929------------------------------------------------------------------------
3030import Data.Bits
3131import Data.Word
32- import Data.Char (intToDigit )
33- import Numeric (showIntAtBase )
32+ import Data.Char ( digitToInt
33+ , intToDigit
34+ )
35+ import Numeric ( readInt
36+ , readHex
37+ , showIntAtBase
38+ )
3439
3540
3641------------------------------------------------------------------------
3742-- | A wrapper around 'Word32' and 'Word64' types
3843data WordF = WordF32 Word32
39- | WordF64 Word64
40- deriving (Eq , Show )
44+ | WordF64 Word64
45+ deriving (Eq , Show )
4146
4247
4348------------------------------------------------------------------------
@@ -69,6 +74,9 @@ dropBits n = (flip shiftL) n . (flip shiftR) n
6974-----------------------------------------------------------------------
7075-- Functions for handling binary representations
7176
77+ binToWord :: Num a => String -> a
78+ binToWord b = fst $ head $ readInt 2 (`elem` " 01" ) digitToInt b
79+
7280wordToBin :: (Show a , Integral a ) => a -> String
7381wordToBin b = showIntAtBase 2 intToDigit b " "
7482
@@ -78,6 +86,9 @@ validBin = all (`elem` "01")
7886-----------------------------------------------------------------------
7987-- Functions for handling hexadecimal representations
8088
89+ hexToWord :: (Num a , Eq a ) => String -> a
90+ hexToWord s = fst (head (readHex s))
91+
8192wordToHex :: (Show a , Integral a ) => a -> String
8293wordToHex b = showIntAtBase 16 intToDigit b " "
8394
0 commit comments