Rebol Talk Forum  |  REBOL Discussions  |  REBOL Core  |  Topic: management of binary data is driving me crazy. :(
Pages: [1] Print
Author Topic: management of binary data is driving me crazy. :(  (Read 723 times)
bouba
Newbie
*
Offline Offline

Posts: 10


View Profile
management of binary data is driving me crazy. :(
« on: July 12, 2006, 07:05:18 AM »

Hello all. :)

So far, it has taken me a lot of time to manage the decoding of a protocol (named ASTERIX) using Rebol while the rest of the code was quite simple ...

Problems I encountered are :

- How do logic operators exactly work on binary data?
Code:
>> and #{000F} #{03}
== #{000F}
I would have expected as a result #{0003} .... seems in fact that the operator was applied only on the "first" byte, is this asumption correct?

- How can I simply write an "AND" operation between an integer and a binary!
Tried the to-hex function but no luck, result is an issue! and "AND" fails. :(
What exaclty is an issue!? shouldn't the result have more meaning as a binary!?

Also, trying to "convert" an integer in binary form, I fell on another problem, as to-binary in fact converts first the integer in string form before conversion in binary ...
The only solution I found was to use a trick which is I suppose totally platform-dependant :
Code:
bin: reverse third make struct! [i [int]] reduce [my-int-value]

This far, I am crying to get a pack/unpack system equivalent to the ruby one as these problems only hide other ones when I will have to extract 3 bits from a 24 bits word ....

So my question now :o)
As anyone already developped anything related to byte/bit manipulation?

Thanks by advance.

Juan-Carlos




Logged
Graham
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: management of binary data is driving me crazy. :(
« Reply #1 on: July 13, 2006, 05:14:50 AM »

I haven't followed it, but there's a long thread on binary manipulation on the Rebol3 world.  But it's not currently public ...
Logged

Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Re: management of binary data is driving me crazy. :(
« Reply #2 on: July 13, 2006, 06:09:01 AM »

- How do logic operators exactly work on binary data?

Just remember that a binary! is a string of bytes, not an integer. So logic operators work on the bytes. #{03} is not the same as #{0003}; the former is just one byte, while the latter is two bytes long.

- How can I simply write an "AND" operation between an integer and a binary!

In this case REBOL is a bit lacking, because of this asymmetry:

Code:
>> to integer! #{0000000F}
== 15
>> to binary! 15
== #{3135}

It has been requested many times that this behavior should change, and I think it eventually will. Right now you can only workaround it:

Code:
>> debase/base to-hex 15 16
== #{0000000F}

So, you have two possibilities: convert the binary to integer, or convert the integer to binary; e.g. if you want to AND #{0000000F} and 3 you can do either:

Code:
>> (to integer! #{0000000F}) and 3
== 3
>> #{0000000F} and (debase/base to-hex 3 16)
== #{00000003}
Logged
bouba
Newbie
*
Offline Offline

Posts: 10


View Profile
Re: management of binary data is driving me crazy. :(
« Reply #3 on: July 14, 2006, 03:03:43 AM »

Thanks a lot for the clarifications, I forgot the existence of debase somewhere. ^^
I will also check AltME, see if there exists my gold mine.
Logged
Pages: [1] Print 
Rebol Talk Forum  |  REBOL Discussions  |  REBOL Core  |  Topic: management of binary data is driving me crazy. :(
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2008, 01:09:09 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2293 Posts in 593 Topics by 3749 Members
Latest Member: irotlydor

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc