Or the packed-binary package on PLaneT (<a href="http://planet.racket-lang.org/display.ss?package=packed-binary.plt&owner=williams">http://planet.racket-lang.org/display.ss?package=packed-binary.plt&owner=williams</a>) that is useful for reading binary formatted files. From the package description:<br>
<br>Performs conversions between Racket values and C structs represented as
byte strings. It also provides read and write routines to perform these
conversions directly to/from binary files. It uses format strings as compact descriptions of the layout of the C structs and the intended
conversion to/from Racket values. This can be used in handling binary
data stored in files or from network connections, among other sources.<br><br>Doug<br><br><div class="gmail_quote">On Tue, Oct 11, 2011 at 8:46 AM, Tony Garnock-Jones <span dir="ltr"><<a href="mailto:tonyg@ccs.neu.edu">tonyg@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi Nicolas,<br>
<br>
On 2011-10-08 12:41 PM, <a href="mailto:nicolas.oury@gmail.com">nicolas.oury@gmail.com</a> wrote:<br>
> I am trying to write a small implementation of Protocol Buffers<br>
> ( <a href="http://code.google.com/p/protobuf/" target="_blank">http://code.google.com/p/protobuf/</a> ) and I have difficulties<br>
> with bit manipulations, especially to transform a negative integer into<br>
> a series of bytes and back.<br>
<br>
You might also be interested to try out (require (planet<br>
tonyg/bitsyntax)). The documentation is at<br>
<a href="http://planet.racket-lang.org/package-source/tonyg/bitsyntax.plt/3/2/planet-docs/manual/index.html" target="_blank">http://planet.racket-lang.org/package-source/tonyg/bitsyntax.plt/3/2/planet-docs/manual/index.html</a><br>
<br>
If, for example, you wanted to parse a little-endian 32-bit length<br>
prefixed blob from a packet, you might write<br>
<br>
(bit-string-case packet<br>
([ (len :: little-endian integer bits 32)<br>
(body :: binary bytes len) ]<br>
body))<br>
<br>
The library supports arbitrary-width integers, and 32- or 64-bit floats.<br>
It uses the primitives that Matthew mentioned internally.<br>
<br>
Regards,<br>
Tony<br>
_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
</blockquote></div><br>