haskell - How do I convert 4 bytes of a ByteString to an Int? -



haskell - How do I convert 4 bytes of a ByteString to an Int? -

how can convert bytestring int?

i have next 4 bytes want convert (it represents size in bytes of .bmp file):

"v\soh\nul\nul"

which know equals 374

for binary parsing, have @ binary bundle - http://hackage.haskell.org/package/binary

it defines get monad, can write like:

data header { ftype :: bytestring, size_ :: word32, reserved_ :: bytestring, offset_ :: word32 } parseheader = ft <- getbytestring 2 size <- getword32le reserved <- getbytestring 4 offset <- getword32le homecoming $ header ft size reserved offset

and later:

main = bytes <- hgetcontents handle allow header = runget parseheader bytes ...

haskell

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -