[racket] Low level manipulation on numbers

From: Tony Garnock-Jones (tonyg at ccs.neu.edu)
Date: Tue Oct 11 10:46:42 EDT 2011

Hi Nicolas,

On 2011-10-08 12:41 PM, nicolas.oury at gmail.com wrote:
> I am trying to write a small implementation of Protocol Buffers
> (   http://code.google.com/p/protobuf/  ) and I have difficulties
> with bit manipulations, especially to transform a negative integer into
> a series of bytes and back.

You might also be interested to try out (require (planet
tonyg/bitsyntax)). The documentation is at

If, for example, you wanted to parse a little-endian 32-bit length
prefixed blob from a packet, you might write

(bit-string-case packet
  ([ (len :: little-endian integer bits 32)
     (body :: binary bytes len) ]

The library supports arbitrary-width integers, and 32- or 64-bit floats.
It uses the primitives that Matthew mentioned internally.


Posted on the users mailing list.