64 lines · 1.5 KB · Text
RawDownload
module Utils.Hex import Data.Primitives.Views exporthexDigit : Int -> CharhexDigit 0 = '0'hexDigit 1 = '1'hexDigit 2 = '2'hexDigit 3 = '3'hexDigit 4 = '4'hexDigit 5 = '5'hexDigit 6 = '6'hexDigit 7 = '7'hexDigit 8 = '8'hexDigit 9 = '9'hexDigit 10 = 'a'hexDigit 11 = 'b'hexDigit 12 = 'c'hexDigit 13 = 'd'hexDigit 14 = 'e'hexDigit 15 = 'f' ||| Convert a positive integer into a list of (lower case) hexadecimal charactersexportasHex : Int -> StringasHex n = pack $ asHex' n []  where    asHex' : Int -> List Char -> List Char    asHex' 0 hex = hex    asHex' n hex with (n `divides` 16)      asHex' (16 * div + rem) hex | DivBy {div} {rem} _ = asHex' div (hexDigit rem :: hex) exportfromHexDigit : Char -> Maybe IntfromHexDigit '0' = Just 0fromHexDigit '1' = Just 1fromHexDigit '2' = Just 2fromHexDigit '3' = Just 3fromHexDigit '4' = Just 4fromHexDigit '5' = Just 5fromHexDigit '6' = Just 6fromHexDigit '7' = Just 7fromHexDigit '8' = Just 8fromHexDigit '9' = Just 9fromHexDigit 'a' = Just 10fromHexDigit 'b' = Just 11fromHexDigit 'c' = Just 12fromHexDigit 'd' = Just 13fromHexDigit 'e' = Just 14fromHexDigit 'f' = Just 15fromHexDigit _ = Nothing exportfromHexChars : List Char -> Maybe IntfromHexChars = fromHexChars' 1  where    fromHexChars' : Int -> List Char -> Maybe Int    fromHexChars' _ [] = Just 0    fromHexChars' m (d :: ds) = pure $ !(fromHexDigit (toLower d)) * m + !(fromHexChars' (m*16) ds) exportfromHex : String -> Maybe IntfromHex = fromHexChars . unpack

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t