Setting a string into a hexidecimal value

M

Misu

Guest
I am trying to change a number value into its corresponding character hexidecimal value for use as my own custom file encryption. I am trying to figure out if there is a possibility to assign a string to a hexidecimal like so:

"00F8" into $00F8

These are NOT colours by the way. They are special characters for text.

This is something experimental, I am not doing anything in specific. Just want to know the possibilities. Thanks in advance. :)
 
P

PandaPenguin

Guest
yourVariable = "$" + string(yourValue)

yourValue can be anything from pure numbers to mixed letters/numbers

EDIT: or I misread your question :p
 
Last edited by a moderator:

Tthecreator

Your Creator!
Just convert it to a number?
The character A starts at asci 65. the 0 at 48. Your number is thus:
Code:
char=//some for loop looping trough characters
var asci = ord(char)
if asci<65 then{
number = asci-48
}else{
number = asci-65
}
Then you can add those numbers using multiplication:
Code:
finalnumber = number4 * (16*16*16) + number3 * (16*16) + number2 * (16) + number1
I hope that helps you.
 
M

Misu

Guest
@PandaPenguin I already tried that but it returns me in blank. If I do $00F8 normally, it would display it. However, when I did "$"+"00F8" is did not.

@Tthecreator That only applies to ASCII. I am using UTC-8, which means I need to use special characters outside the 255 limit.
 
P

PandaPenguin

Guest
@PandaPenguin I already tried that but it returns me in blank. If I do $00F8 normally, it would display it. However, when I did "$"+"00F8" is did not.

@Tthecreator That only applies to ASCII. I am using UTC-8, which means I need to use special characters outside the 255 limit.
ok so "stitching" together a string doesn't work as it gets recognized as string and not hex value... I'm not sure that GML supports any more hexadecimal variable processing other than the color coding
 

Tthecreator

Your Creator!
what happens if you just put the byte numbers back together like this:
Code:
string=""
c1 = number2 * (16) + number1
c2 = number4 * (16) + number3
string=chr(c1)+chr(c2)
I don't actually know if chr does something special with your data, but I hope it will just throw any number below 255 into string format, whatever it means. That means that utf-8 formatting should be preserved. (if my assumptions are right.)
 
M

Misu

Guest
Nevermind. I found out that I had to use only chr() alone and it returns me what I needed. My bad. Thanks Guys!
 

Tthecreator

Your Creator!
good, but that will not actually work with utf-8 I just found out. Only with plain unicode characters, but that's not an actual format.
The utf-8 format needs to be converted to unicode, which is some work on itself.
 
Top