Page 1 of 1
Convert number in ascii to hex value
Posted: Fri Nov 10, 2023 7:35 pm
by unartic
Hi!
If I have these bytes: $32 $36 $30 $31 which represent the value 2601.
How can I convert it to the corresponding hex value: $0A29
Re: Convert number in ascii to hex value
Posted: Fri Nov 10, 2023 7:41 pm
by ahenry3068
What language are you using ?
Re: Convert number in ascii to hex value
Posted: Fri Nov 10, 2023 7:41 pm
by unartic
Assembly ca65
Re: Convert number in ascii to hex value
Posted: Fri Nov 10, 2023 7:44 pm
by ahenry3068
In BASIC You use VAL(String$)
So A= VAL("2601")
Then in Numeric format 2601 and your Hex value are the same.
To represent it as HEX again you would use HEX$(A)
Re: Convert number in ascii to hex value
Posted: Fri Nov 10, 2023 7:44 pm
by ahenry3068
unartic wrote: ↑Fri Nov 10, 2023 7:41 pmAssembly ca65
I think theirs a ROM routine, let me look.
Re: Convert number in ascii to hex value
Posted: Fri Nov 10, 2023 7:49 pm
by ahenry3068
I couldn't find one
.. I think you need to get on Discord and ask this question in ASM-DEV. I really don't know enough about assembly yet to help. I know how its done in High level language. I was hoping I could find a ROM call for you.
Re: Convert number in ascii to hex value
Posted: Fri Nov 10, 2023 9:05 pm
by Stefan
Re: Convert number in ascii to hex value
Posted: Sat Nov 11, 2023 5:44 am
by Stefan
An example based on the above article:
https://github.com/stefan-b-jakobsson/x ... r/util.inc
The function util_str_to_bcd converts a NULL terminated ASCII/PETSCII string to Binary Coded Decimal format.
And the function util_bcd_to_bin converts a BCD value to a binary number that the 65c02 can use