Convert char string in hex ?
vincen
Posts: 526
Hey
ok it's probably a stupid question but I'm unable to find the way to convert literally a char string in hex. For example I have a string 0AB0FF that I need to convert in hex type au $0A,$B0,$FF
Thanks
Vincèn
ok it's probably a stupid question but I'm unable to find the way to convert literally a char string in hex. For example I have a string 0AB0FF that I need to convert in hex type au $0A,$B0,$FF
Thanks
Vincèn
0
Comments
Here is a small section of code that will take the ascii hex you provide and populate an array with the decimal numbers you want. Remember, an integer can be represented as decimal or as hex interchangeably -- i.e. there is no difference to the process between decimal and hex.
If you run this on the text you proposed, you get a three element array containing {$A,$B0,$FF}
or {10,176,255} Type as either 8 bit character arrays or integer arrays as desired.
edited:
hextoi() does indeed return a 32 bit unsigned integer. But, if you assign the result to a 16 bit integer, as I dis -- well, that's clear.
So, it's probably easier to use hextoi() on the whole string and then extract what is wanted by using bitwise and and shifting bits.