TIB: Re: Hex Converter


[Prev][Next][Index][Thread]

TIB: Re: Hex Converter




Which calculator do you have?  If it's the 85 or higher, decimal/hex
conversions are built in.  If it's the 83, it's already been done.  In
others words, your program is unnecessary.

But if you still want to write this program, it can easily be done.  The key
it to work backwards: i.e., start at the rightmost digit.

// Assume that the input, Num, is an integer
{0} -> DIGIT
1 -> I
While Num>0
16fPart(Num/16) -> DIGIT(I)    // B*fPart(A/B) is equivalent to better
calcs' mod(A,B) function
iPart(Num/16) -> Num
I+1 -> I
End

This will store a list of the hex digits of Num, in reverse order, in the
list DIGIT.
For example, if Num=1000 (3CAh), DIGIT will be {10, 12, 3} after this code
is executed.

All that's left is to output the hex number.  Remember that, on the 83 and
higher, sub("0123456789ABCDEF",N+1,1) is the hex representation of the digit
N.  The 82 doesn't have sub( ), so if you're writing for that calculator,
you'll need to use If statements instead.

If DIGIT(I)<10
Output(_,__,DIGIT(I
If DIGIT(I)=10
Output(_,__,"A
If DIGIT(I)=11
Output(_,__,"B
// etc.

Numbers with fractional parts can be done in a similar matter.  You have to
consider the integer and decimal parts separately.  For the decimal part,
the loop will involve multiplication by 16 instead of division.

Or, if you decide that's too much trouble, click here:
http://www.ticalc.org/pub/83/basic/math/baseconv4.zip

----- Original Message -----
From: <Stephen432@aol.com>
To: <ti-basic@lists.ticalc.org>
Sent: Tuesday, October 10, 2000 15:06
Subject: TIB: Hex Converter


>
> I'm trying to make a converter from decimal to hexadecimal.  Vie written
an
> algorithm to convert the first hexadecimal digit.  I need help starting
the
> second digit because it may flow into multiple digits.  Any Ideas?
>



References: