Hello <[EMAIL PROTECTED]>

Well enbase and debase do have some bugs that have been reported to
feedback, but your example is not a bug, although one could question the way
REBOL currently handles these matters.

Enbase/base takes a string arg and converts each byte of the string to a
string representation of the byte in one of the supported bases.

In your example the ascii character "2" is a byte with the decimal value 50
and the hexadecimal value 32 and a binary value of 00110010.

>> to-char 50
== #"2"

>> to-string to-char 50
== "2"

>> enbase/base "2" 2
== "00110010"

>> enbase/base "2" 16
== "32"

So this is correct because the binary string "00110010" corresponds to the
hex string "32".

If you want the answer as a REBOL binary! value of character 50 dec == 32
hex == "2" ascii == 00110010 bin

>> to-binary "2"          ;REBOL binary is displayed as 2 hex digits but is
just 1 byte and same byte as #"2"
== #{32}

Perhaps you wanted the binary string value for the ascii character with
index 2 which corresponds to a byte with the decimal value 2, hex value 2,
and binary value 00000010?

>> enbase/base to-string to-char 2 2      ;a little awkward
== "00000010"

If you want the answer as a REBOL binary! value use

>> to-binary to-string to-char 2
== #{02}

I have attached a very short script which prints an ascii table for REBOL
with dec, char, hex, and binary forms.

HTH  if not please ask more questions.

-Larry

-----------------code--------------------------

REBOL [
 Title: "Binary-string stuff"
 Author: "Larry Palmiter"
 File: %binarystring.r
 Date: 16-Jul-2000
]

repeat j 256 [
 i: j - 1
 print reduce [
  i
  mold hs: copy skip to-string to-hex i 6
  mold to-char i
  do join "#{" reduce [hs "}"
  ]
 ]
]

Original message:

> Does anyone know if enbase/base refinement has a bug.  When I do the
> following:
>
> a: "2"
> enbase/base a 2
>
> I get:
>
> >>"00110010"
>
> This must be a bug or I need more understanding.
>
>
> --
> Is your email secure? http://www.pop3now.com
> (c) 1998-2000 secureFront Technologies, Inc. All rights reserved.
>
REBOL [
        Title: "Binary-string stuff"
        Author: "Larry Palmiter"
        File: %binarystring.r
        Date: 16-Jul-2000
]

repeat j 256 [
        i: j - 1
        print reduce [
                i
                mold hs: copy skip to-string to-hex i 6
                mold to-char i
                do join "#{" reduce [hs "}"
                ]
        ]
]

Reply via email to