[Coco] OS9 HEX to DECIMAL conversion.

L. Curtis Boyle curtisboyle at sasktel.net
Wed May 16 13:28:12 EDT 2018


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
>> 



More information about the Coco mailing list