Jump to content
IGNORED

Convert HEX directly to DEC?


Larry
 Share

Recommended Posts

With the "second generation" BASICs (BXL, BXE, TBXL, Altirra Basic, etc.), is it possible to directly convert a HEX number into DEC? All of these BASICs have a HEX$ function, and I thought there was a way to use the VAL function to do the reverse conversion. But there doesn't seem to be. (I know there is a short routine that can be used, but as I said, is there a direct way?)

 

-Larry

Link to comment
Share on other sites

?$ABCD maybe :)

 

EDIT:

 

and if you mean to convert a hex number to a value (not just to a dec string), in TBXL there is DEC(), for example A=DEC("ABCD"). In BXE the VAL function you mention should work similarly, it just requires "$" in front of the digits.

Edited by drac030
Link to comment
Share on other sites

With the "second generation" BASICs (BXL, BXE, TBXL, Altirra Basic, etc.), is it possible to directly convert a HEX number into DEC? All of these BASICs have a HEX$ function, and I thought there was a way to use the VAL function to do the reverse conversion.

 

I use BASIC XL. Internally, every number is stored as a floating point decimal number, so there really is no "hexadecimal" number.

.

A=$FEDC

Ready
?A
65244

Ready
?$BA98
47768

Ready

.

So, there is no need to convert a hexadecimal numeric constant since it is automatically converted to decimal when it is used or assigned to a variable.

 

 

Turning a string representing a hex value into decimal works (in BASIC XL) with VAL(), but it requires a leading dollar sign.

.

?VAL("$01FF")
511

Ready
Link to comment
Share on other sites

in TBXL there is DEC(), for example A=DEC("ABCD").

 

Be aware that this only functions correctly if your character string data is uppercase. I found this out when attempting to convert a lot of text files that were mostly hex data, where some of the files used all lower-case.

Link to comment
Share on other sites

Thanks for the replies! This all started when I wanted a quick way to convert some hex numbers from a screen print. But as usual, I got the info I needed and learned more from our members as a bonus!

P.S. while looking for an quick solution, I found this little Atari BASIC program from Analog. This was the best one I found in my archives, but it doesn't include a decimal to hex routine. This was from Analog #17 from the BASIC Training column. It is set up to loop for repetitive conversion values.

-Larry

HexDec.atr

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...