Consider this:

>> print a
#{0123456789ABCDEF}
>> length? a
== 8
>> a: 16#{01 23 45 67 89 ab cd ef}      ; spaces don't matter
== #{0123456789ABCDEF}
>> length? a
== 8

Does the second form give you a hint?  Binaries (in REBOL) are multiple of
8-bit quantites.  Consider the following also:

>> b: 2#{0101010101}    ; NG: IT HAS TEN BINARY DIGITS
** Syntax Error: Invalid binary -- 2#{0101010101}.
** Where: (line 1) b: 2#{0101010101}
>> b: 2#{01010101}      ; OK: IT HAS EIGHT BINARY DIGITS
== #{55}
>> b: 2#{010101011111111100000000}      : 24 (3x8) BITS
== #{55FF00}

The normal base is 16 (hex), and so there are two hex characters for each entry.

To see why your code is producing the results it is, consider this:

>> print a
#{0123456789ABCDEF}
>> foreach char a [ print char ]
1       ; 01h
35      ; 23h
69      ; 45h
103     ; 67h
137     ; 89h
171     ; ABh
205     ; CDh
239     ; EFh

Look familiar?  Like the ASCII chars that make up your final string?

Consider this too:

>> for i 1 length? a 1 [ print a/:i ]
1
35
69
103
137
171
205
239

And this:

>> for i 1 length? a 1 [ print to-binary to-string to-char a/:i ]
#{01}
#{23}
#{45}
#{67}
#{89}
#{AB}
#{CD}
#{EF}

Finally:

>> b: make binary! none
== #{}
>> foreach char a [ append b to-binary to-string to-char char ]
== #{0123456789ABCDEF}
>> print b
#{0123456789ABCDEF}

I'm a newbie too... so there very well may be another (simpler) way to this
result! :)  But it seems to have to do with the 'type? that things are and
what functions require as arguments.  Good luck.

Russ
--------------------------------------
At 02:30 PM 10/23/99 -0700, you wrote:
>Here's some interesting stuff in re your second question - not an answer,
>but may give you some insight.
>
>>> a: 16#{0123456789abcdef}
>== #{0123456789ABCDEF}
>>> type? a
>== binary!
>>> first a
>== 1
>>> second a
>== 35
>>> type? first a
>== integer!
>>> third a
>== 69
>>> ; note 35 = $23, $ meaning hexadecimal.  Also 69 = $45.
>
>Apparently pairs of char's in you definition of a were interpreted as
>hexadecimal 2 digit numbers!
>
>$ == hex is not REBOL usage.
>
>Russell, [EMAIL PROTECTED]
>----- Original Message -----
>From: <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Saturday, October 23, 1999 5:47 AM
>Subject: [REBOL] Newbie questions: blocks, lists & append hex
>
>
>> Hi
>> Two newbie questions:
>>
>> 1st) Which is the difference between a BLOCKs and LISTs ?
>>
>> 2nd) How can copy a hex string into another hex string USING APPEND?
>> The following don't works:
>>
>> >> a: 16#{0123456789abcdef}
>> == #{0123456789ABCDEF}
>> >> b: 16#{}
>> == #{}
>> >> foreach char a [append b char]
>> == #{3133353639313033313337313731323035323339}
>>
>> Thank you
>>
>>
>> --
>> Luis Marzulli
>> e-mail: [EMAIL PROTECTED]
>> Caracas, VENEZUELA
>> ----------------------------------------------------------
>> Earn money when you or your friends are on the Web
>> click --> http://www.alladvantage.com/go.asp?refid=BXX890
>>
>
>
>

Reply via email to