General binary conversions

Carl Sassenrath, CTO
REBOL Technologies
5-May-2010 19:24 GMT

Article #0317
Main page || Index || Prior Article [0316] || Next Article [0318] || 11 Comments || Send feedback

As you know, R3 includes various functions for conversion to an from binary values. For example,

>> to-binary 1
== #{0000000000000001}
>> to-integer #{0000000000000001}
== 1

However, it must be pointed out that this technique is not designed for general purpose conversions. It's a specific conversion method that comes from how we extend the definition of the to function... but in a very restricted way.

Because many programmers want direct-to-bits conversions between datatypes and binary representations, a more extensive method is required. In R2, one method was the struct! datatype that mapped types to binary.

I suggest that we need something similar in R3. The method needs to be flexible enough to deal with binary sizes, byte order, and sign extensions. In this way, we can map to and from any binary series more directly.

This is a much better solution than trying to piece together mezzanine functions that slice and dice to and form binaries to accomplish the same end.

If we want to come up with an adequate definition, which will no doubt be dialect-based like struct or vector definitions, I'd like to get it into A99 for you to test out.


Updated 30-Mar-2017 - Edit - Copyright REBOL Technologies -