Created
February 2, 2017 23:47
-
-
Save JoshuaGross/313bfa6f0de5413eeb2d87c21024f6c9 to your computer and use it in GitHub Desktop.
Use Haskell to display a ByteString as hex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- can be used in ghci | |
import qualified Data.ByteString as B | |
import Numeric (showHex) | |
import qualified Data.ByteString.Lazy as LBS | |
import qualified Data.Binary as B | |
-- encode some object to a binary ByteString | |
let s = (B.encode someObjectThatHasBinaryInstance) | |
let prettyPrint = P.concatMap ((\x -> "0x"++x++" ") . flip showHex "") . B.unpack :: B.ByteString -> String | |
prettyPrint (LBS.toStrict s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This one seemed to work for me, but requires Printf.