diff options
Diffstat (limited to 'utils.hs')
| -rw-r--r-- | utils.hs | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -1,6 +1,7 @@ module Utils where import Control.Applicative (ZipList (ZipList, getZipList)) +import Data.Char (digitToInt) (.>) = flip (.) @@ -46,4 +47,11 @@ takeUntil _ [] = [] takeUntil p (x : xs) = x : if p x then takeUntil p xs else [] fromSymEither (Left x) = x -fromSymEither (Right x) = x
\ No newline at end of file +fromSymEither (Right x) = x + +-- | Convert binary (list of zeros and ones) to decimal +binaryToInt :: String -> Int +binaryToInt = reverse .> binaryToIntRev + +binaryToIntRev [] = 0 +binaryToIntRev (x : xs) = digitToInt x + 2 * binaryToIntRev xs |
