Convert number in ascii to hex value

All aspects of programming on the Commander X16.
Post Reply
unartic
Posts: 145
Joined: Sat Oct 28, 2023 3:26 pm

Convert number in ascii to hex value

Post 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
User avatar
ahenry3068
Posts: 1194
Joined: Tue Apr 04, 2023 9:57 pm

Re: Convert number in ascii to hex value

Post by ahenry3068 »

What language are you using ?
unartic
Posts: 145
Joined: Sat Oct 28, 2023 3:26 pm

Re: Convert number in ascii to hex value

Post by unartic »

Assembly ca65
User avatar
ahenry3068
Posts: 1194
Joined: Tue Apr 04, 2023 9:57 pm

Re: Convert number in ascii to hex value

Post 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)
User avatar
ahenry3068
Posts: 1194
Joined: Tue Apr 04, 2023 9:57 pm

Re: Convert number in ascii to hex value

Post by ahenry3068 »

unartic wrote: Fri Nov 10, 2023 7:41 pmAssembly ca65

I think theirs a ROM routine, let me look.
User avatar
ahenry3068
Posts: 1194
Joined: Tue Apr 04, 2023 9:57 pm

Re: Convert number in ascii to hex value

Post 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.
Stefan
Posts: 465
Joined: Thu Aug 20, 2020 8:59 am

Re: Convert number in ascii to hex value

Post by Stefan »

I’ve based such code on this old article:

https://www.atarimagazines.com/compute/ ... OUTINE.php
Stefan
Posts: 465
Joined: Thu Aug 20, 2020 8:59 am

Re: Convert number in ascii to hex value

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