[Coco] OS9 HEX to DECIMAL conversion.
James Jones
jejones3141 at gmail.com
Wed May 16 14:19:11 EDT 2018
Tried it out. VAL("$61A80") gives an error 67, "illegal argument".
VAL("A80") prints as 2688., so VAL() returns a REAL, which I guess it has
to for consistency with other BASICs. Hex PRINT USING output claims to be
fine with printing a REAL, but perhaps the VAL() code for hex doesn't
handle values that won't fit in an INTEGER. (What's 61A80? 400000 in hex.)
On Wed, May 16, 2018 at 12:28 PM, L. Curtis Boyle <curtisboyle at sasktel.net>
wrote:
> No, it only converts hex to decimal. But that solves half of what he wants
> to accomplish. It works with either the user entering “$0010” at an input
> prompt, or you can take string and do VAL(“$”+string).
>
>
> L. Curtis Boyle
> curtisboyle at sasktel.net
>
>
>
> > On May 16, 2018, at 10:43 AM, Wayne Campbell <asa.rand at gmail.com> wrote:
> >
> > Curtis,
> >
> > The $ operator, so far as I've ever been able to determine, does not
> > convert decimal to hex. What it does is tells Basic09 to treat the number
> > following it as a hexadecimal number. This means that $10 is stored in
> the
> > i-code as 0010, not 000A.
> >
> > On Wed, May 16, 2018, 8:02 AM L. Curtis Boyle <curtisboyle at sasktel.net>
> > wrote:
> >
> >> Wayne is correct in that INTEGER is signed only. So if you input a value
> >> of $8000 or more, it will become a negative number.
> >> Having said that, BASIC09 does have a built in hex to decimal
> conversion.
> >> You just need to add a ‘$’ at the start of the number. You can either
> >> prompt the user to ‘Add a ‘$’ in front of the number for hexadecimal’,
> or
> >> you can check if the first character in your string (with
> >> LEFT$(stringvar,1)) is not a ‘$’, and then add it your self. When you
> do a
> >> VAL(stringvar), it will return the decimal version. (I should note,
> because
> >> of how BASIC09’s internal variable analyzing routine works, that the
> signed
> >> 16 bit limit even applies to you assigning it to a REAL variable;
> BASIC09
> >> internally treats ‘$’ numbers as 16 bit signed bits irregardless;
> Assigning
> >> it to a REAL makes it the same number as it does with INTEGER, just in
> REAL
> >> format).
> >>
> >> L. Curtis Boyle
> >> curtisboyle at sasktel.net
> >>
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>
More information about the Coco
mailing list