+Larry Posted October 17, 2015 Share Posted October 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
drac030 Posted October 17, 2015 Share Posted October 17, 2015 (edited) ?$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 October 17, 2015 by drac030 Quote Link to comment Share on other sites More sharing options...
Bryan Posted October 17, 2015 Share Posted October 17, 2015 Nevermind, I missed what you're asking. You want to convert in BASICs that already support HEX. Quote Link to comment Share on other sites More sharing options...
+Larry Posted October 17, 2015 Author Share Posted October 17, 2015 ?$ABCD maybe Yes! That works fine! So for example, DNUM=$A9:? DNUM results in 169 being printed. Thanks -- I'll make a note in my BXL manual! -Larry Quote Link to comment Share on other sites More sharing options...
kenjennings Posted October 17, 2015 Share Posted October 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
+MrFish Posted October 18, 2015 Share Posted October 18, 2015 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. Quote Link to comment Share on other sites More sharing options...
drac030 Posted October 18, 2015 Share Posted October 18, 2015 Yes, that is a known TBXL bug, thanks for reminding about it. Quote Link to comment Share on other sites More sharing options...
+Larry Posted October 18, 2015 Author Share Posted October 18, 2015 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 Quote Link to comment Share on other sites More sharing options...
+MrFish Posted October 18, 2015 Share Posted October 18, 2015 (edited) BASIC Turbocharger has routines for both DEC -> HEX and HEX -> DEC. That's where I got the routine I'm using from. [Edit: I should add, that the HEX -> DEC routine here will work with upper-case or lower-case input.] Atarimania - BASIC Turbocharger Edited October 18, 2015 by MrFish Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.