[racket] Low level manipulation on numbers

From: nicolas.oury at gmail.com (nicolas.oury at gmail.com)
Date: Sat Oct 8 14:24:00 EDT 2011

Thank you so much for your very quick answer.
It seems that the conversion to and from bytes are what I was looking for.
With that, it is quite easy to do all the manipulations I want.



On Sat, Oct 8, 2011 at 6:57 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:

> At Sat, 8 Oct 2011 17:41:35 +0100, "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.
> >
> > I can not find an implementation of a non-arithmetic shift for fixnums,
> and
> > a way to specify which size of fixnum to construct.
> There aren't different sizes of fixnums. When you want to convert an
> exact integer to bytes, then `integer->integer-bytes' lets you specify
> the size.
> There also isn't a logical shift operator, if I understand what you're
> after. If you work with positive integers, then `arithmetic-shift'
> (plus `bitwise-and'?) behaves like a logical shift. If you want
> logical-shift effects for finite 2's complement representations, then
> you probably don't really want to work on fixnum representations, which
> are 63 or 31 bits, but instead some power of 2 via bitwise operations
> like `bitwise-ior', `bitwise-and', and arithmetic shifts of negative
> numbers. Note also that `integer-bytes->integer' lets you say whether
> to interpret a set of bytes as unsigned or as 2's complement.
> > I can't also find an easy way to get the byte representation of flonums.
> `real->floating-point-bytes'

Sent from an IBM Model M, 15 August 1989.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111008/b9765191/attachment.html>

Posted on the users mailing list.