Working with binary data


Stream words on binary streams only read and write byte arrays. Packed binary integers can be read and written by converting to and from sequences of bytes. Floating point numbers can be read and written by converting them into a their bitwise integer representation (Floats).

There are two ways to order the bytes making up an integer; little endian byte order outputs the least significant byte first, and the most significant byte last, whereas big endian is the other way around.

Consider the hexadecimal integer 0xcafebabe. Little endian byte order yields the following sequence of bytes:
Byte:1234
Value:bebafeca

Compare this with big endian byte order:
Byte:1234
Value:cafebabe

Two words convert a sequence of bytes into an integer:
be> ( seq -- x )

le> ( seq -- x )


Two words convert an integer into a sequence of bytes:
>be ( x n -- byte-array )

>le ( x n -- byte-array )