How to convert hexadecimal characters back in MSX basic

ページ 1/3
| 2 | 3

By Mafcase

Champion (258)

Mafcase さんの画像

11-01-2022, 17:12

'The hexadecimal representation of 127 is 7F'

Is there any way to convert the hexidecimal output back to it's original form?
So: 7F (hexadecimal) = 127

Thanks in advance!

ログイン/登録して投稿

By theNestruo

Champion (430)

theNestruo さんの画像

11-01-2022, 17:34

Some examples (direct values, numeric variables, string variables, etc.): https://msxpen.com/codes/-Mt8zELDCkcccBKxLzlW

By TheKid

Paragon (1238)

TheKid さんの画像

11-01-2022, 17:42

Print &H7F

By Mafcase

Champion (258)

Mafcase さんの画像

11-01-2022, 19:54

Thank you for these answers!

Do you know how to convert the character back from (when it's stored in) a string? (a$=f7 to A=127

By Grauw

Ascended (10821)

Grauw さんの画像

11-01-2022, 19:58

A=VAL("&H"+A$)

See https://www.msx.org/wiki/VAL

By gdx

Enlighted (6438)

gdx さんの画像

12-01-2022, 01:20

About hexadecimal conversion, does anyone know why this program is not working and how to make it work?

10 L=PEEK(&HF673)*256+PEEK(&HF672): PRINT HEX$(L)
20 FOR M=&HC000 TO L: PRINT HEX$(M): NEXT

At start, L = F360 on a MSX without drive but the loop doen't stop at this value. If I use FOR M=&HC000 TO &hF360, it works.

By pgimeno

Champion (328)

pgimeno さんの画像

12-01-2022, 02:39

The problem is that &HC000 equals -16384, so it's effectively looping from -16384 to 61800.

Try:

10 L=PEEK(&HF673)*256+PEEK(&HF672): IF L>&H7FFF THEN L=L-65536

Or if you know that it's going to be > 7FFF always:

10 L=(PEEK(&HF673)-256)*256+PEEK(&HF672)

By pizzapower

Master (172)

pizzapower さんの画像

12-01-2022, 06:01

gdx wrote:

About hexadecimal conversion, does anyone know why this program is not working and how to make it work?

10 L=PEEK(&HF673)*256+PEEK(&HF672): PRINT HEX$(L)
20 FOR M=&HC000 TO L: PRINT HEX$(M): NEXT

At start, L = F360 on a MSX without drive but the loop doen't stop at this value. If I use FOR M=&HC000 TO &hF360, it works.

Stop converting the addresses to integer. Just use single or double precision directly.

10 L=PEEK(&HF673)*256+PEEK(&HF672): PRINT HEX$(L)
20 FOR M=49152 TO L: PRINT HEX$(M): NEXT

By gdx

Enlighted (6438)

gdx さんの画像

12-01-2022, 08:29

The problem is an hexa value cannot be interpreted as a no signed value. I thought that there would be another solution than a condition or to put the values yourself in decimal. So I'll do it pretty much as Pgimeno advises.

L=PEEK(&HF673)*256+PEEK(&HF672): L=L+(L>&H7FFF)*65536!

By pizzapower

Master (172)

pizzapower さんの画像

13-01-2022, 02:01

gdx wrote:

The problem is an hexa value cannot be interpreted as a no signed value. I thought that there would be another solution than a condition or to put the values yourself in decimal. So I'll do it pretty much as Pgimeno advises.

L=PEEK(&HF673)*256+PEEK(&HF672): L=L+(L>&H7FFF)*65536!

The problem is your starting point is a negative integer and your finishing point is a positive double precision float. If you used the same data type for both ranges of the FOR loop, you wouldn't get this behaviour. For instance:

10 L%=CVI(CHR$(PEEK(&HF672))+CHR$(PEEK(&HF673))): PRINT HEX$(L%)
20 FOR M=&HC000 TO L%: PRINT HEX$(M): NEXT

By gdx

Enlighted (6438)

gdx さんの画像

13-01-2022, 02:07

No and yes it depends on what point you focus. It not work when I use also integer or single/double precision.

Anyway thank for CVI. So the explanation from de wiki is wrong.

https://www.msx.org/wiki/CVI%28%29

ページ 1/3
| 2 | 3