[REBOL] Re: Problem with try [ open/direct/binary tcp://... ] Re:(6)
From: rebol:svendx:dk at: 3-Oct-2000 23:24
Hello [eventi--nyic--com],
On 03-Oct-00, [eventi--nyic--com] wrote:
-- snip --
> I'm having fun with mine, thank you, but I'll let you know if I get stuck ;)
ok :)
> Too bad Gnutella's sucking so bad lately...
yep
> I'm finding that REBOL's a pretty nice tool to get close to the protocol.
> Out of curiosity, how do you reverse byte order, for things like the length
> header? And I havn't seen an elegant way to concatenate binary! type data.
> Join would be nice.
>
>>> probe join #{012345} [ #{0123} ]
> #{012345237B303132337D}
>
>>> ; This makes me cringe
>>> probe to-binary join to-string #{012345} [ to-string #{6798} ]
> #{0123456798}
> == #{0123456798}
yeah, REBOLs build-in binary capabilities are a bit strange sometimes :-/
## to binary! 100
== #{313030}
(same as: to binary! "100")
I use these functions:
int-to-bin: func [int /little-endian /local bin] [
bin: load join "#{" [to-hex int "}"]
either little-endian [
head reverse bin
] [
bin
]
]
bin-to-int: func [bin /little-endian /local int] [
bin: either little-endian [
head reverse copy bin
] [
bin
]
int: (bin/1 * (2 ** 24)) + (bin/2 * (2 ** 16)) + (bin/3 * (2 ** 8)) + bin/4
]
Best regards
Thomas Jensen