Hex variable to ASCII
Hi,
I have a word size variable Myvar=$FE00 and I need to convert it to ASCII hex
like "FE00". After it is converted, I need to store it to an external EEPROM.
Would a STR variable be best. Any ideas how I can do that?
Thanks,
Allan
I have a word size variable Myvar=$FE00 and I need to convert it to ASCII hex
like "FE00". After it is converted, I need to store it to an external EEPROM.
Would a STR variable be best. Any ideas how I can do that?
Thanks,
Allan
Comments
There are several ways you might do this. I'd think about doing it this
way:
Stobyte var byte
Myvar var word
Eeadd var word
Stobyte = myvar.nib0
Eeadd=10 ' eeprom start address
Gosub stonib
Stobyte=myvar.nib1
Eeadd=Eeadd+1
Gosub stonib
Stobyte=myvar.nib2
Eeadd=Eeadd+1
Gosub stonib
Stobyte=myvar.nib3
Eeadd=Eeadd+1
Gosub stonib
... Blah blah blah...
Stonib:
Stobyte=stobyte+"0"
If stobyte<="9" then stonib1
' correct A-F
Stobyte=stobyte+"A"-"0"-10
Stonib1:
WRITE eeadd,stobyte
Return
Or you might want to use a loop and store the number backwards:
For i=1 to 4
stobyte = myvar & $F
gosub stonib
eeadd=eeadd+1
myvar = myvar >>4 ' destroys myvar
Next
Of course, if you wanted it the other way, you could set eeadd to the
top address and subtract one. Its as broad as it is long.
Hope that helps.
Al Williams
AWC
* NEW: PAK-VIa - Read PS/2 keyboards or mice -- double the buffer, lower
current consumption.
http://www.al-williams.com/awce/pak6.htm
>
Original Message
> From: Allan [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=QrzwoHc_UzeVkHiQeumR1Oct7evY9X4aLfmpHLxWuh2kXQxaSA5BDNyuZ_yH5d7wMBKWLXYOxyM]aldobler@s...[/url
> Sent: Friday, August 02, 2002 9:22 PM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Hex variable to ASCII
>
>
> Hi,
> I have a word size variable Myvar=$FE00 and I need to convert
> it to ASCII hex like "FE00". After it is converted, I need
> to store it to an external EEPROM.
> Would a STR variable be best. Any ideas how I can do that?
>
> Thanks,
>
> Allan
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
You and Tracy are always helping to teach us BASICally challenged, 'The Way of
the Stamp'.
Allan (Grasshopper) Dobler
Al Williams wrote:
>
> Hi Allan,
>
> There are several ways you might do this. I'd think about doing it this
> way: