Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to convert hex string to value?

Author
Message
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 29th Mar 2018 02:46 Edited at: 29th Mar 2018 03:33
In DBpro you can convert a hex string to a dword value using 'hex to decimal':

myValue = hex to decimal("0x000000ff")

AGK can convert a value into a hex string:

myString = Hex(255)

does it have any way built in to convert the hex string back into a value without having to roll my own parser? I'm not really seeing anything in the help files.

Thanks all,



It's clunky, but it gets the job done I guess...
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 29th Mar 2018 05:04

I suspect the VAL() function will support not only Decimals but Hex and Binary also.. So give it a try..



PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 29th Mar 2018 05:21 Edited at: 29th Mar 2018 05:22
Quote: "I suspect the VAL() function will support not only Decimals but Hex and Binary also.. So give it a try.."


I did try that before posting, unfortunately it does not seem to.

print(val("0xff"))
print(val("ff"))
print(val("0x0000ff"))

all yield 0
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 29th Mar 2018 05:58 Edited at: 29th Mar 2018 06:01
I think Val will do it but you need to specify the base so 16 in this case.

Val(yourHex$, 16)

Just checked and in fact the example actually shows converting from hex.

https://www.appgamekit.com/documentation/Reference/Core/Val.htm
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 29th Mar 2018 14:43
Oh cool, thanks man. Didn't realize it had an overload
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.

Login to post a reply

Server time is: 2024-04-20 13:05:32
Your offset time is: 2024-04-20 13:05:32