I think the `integer->integer-bytes` function is probably what you want.

Sam

On Mon, Oct 17, 2016 at 8:38 PM, David Storrs <david.sto...@gmail.com> wrote:
> What is the best way to write binary data such that I have control of the
> representation?  Basically, I want the Racket equivalent of the Perl 'pack'
> and 'unpack' functions, where I can do:  pack('C', 202) and get back a
> one-byte binary representation of the decimal number 202 (or pack('s', 202)
> to get a 2-byte version) that I could then write to a port.
>
> The reason that I'm looking for this is that I'm going to be writing binary
> data across the network and I want to be able to control the representation.
> For a fairly trivial example, I want to be able to decide how many bytes the
> number 202 should take up.[1]   Furthermore, I'd like to have an easy way to
> do quick and dirty testing; I thought that writing to a byte string would be
> that way, but I'm not having much success with it, as I haven't figured out
> how to make things go in as raw bytes instead of strings.
>
> I've looked at fasl, binary-class, the implementation of protobuf, and
> everything in the racket-lang docs that I could think of keywords for, with
> no luck.  This feels like it should be a straightforward task, so I'm
> frustrated with myself for not figuring it out more quickly.
>
>
> [1] I keep using the number 202 because that's the size of one particular
> message that I'm using in my text script and I'm trying to do RLE on it.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to