String to hex?
Blitz3D Forums/Blitz3D Programming/String to hex?
| ||
Has anyone written a function to convert a normal (Blitz3d) string to a hex string? I made an attempt at it, but it didn't work out. PRobably because I was just taking random shots into the dark. If you have written such a function, would you please share it up here? |
| ||
Local s$ = "123ttt3" Local i% = Int(s) Print Hex(i) WaitKey() ? |
| ||
Perturbatio: Thanks for the help... but that would be for a hex number to a string :) An example of the output I'm hoping to produce is here: input: "Cube\cube.exe" output: 43 75 62 65 5C 63 75 62 65 2E 65 78 65 My little attempt to get the number value for each letter succeeded, but I was stumped after that. Edit: GARGH! Stupid me! I may have just fixed it myself. Again. I can't be the only person on this forum who always does this. Am I? :S Okay, here *blush* Local s$ = "Cube\cube.exe" Print StrToHex$(s$) WaitKey() Function StrToHex$(InpStr$) ;Convert Ascii string to Hex string for XVI32 Local OutStr$ For a=1 To Len(inpStr$) ca$=Mid(inpStr,a,1) cb=Asc(ca$) OutStr$=OutStr$+RSet(Trim(Hex(cb)),2)+" " Next Return Mid(OutStr$,1,Len(outStr$)-1);Remove final space... End Function |
| ||
So what you mean is you want to convert each character in a string to the hex value of their ascii equivalents?Local s$ = "Cube\cube.exe" Local count = 1 While count <= Len(s) Print Right(Hex(Asc(Mid(s, count, 1) )),2) count = count + 1 Wend WaitKey() |
| ||
Yup, I just did it... 3 minutes after you. Thanks anyway! I hate solving my own problems. I just shouldn't give up on things because my past self was too thick to figure them out. James, be a nice person and delete this thread. Please??? |