Code archives/Miscellaneous/Convert hex string to byte array
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This won't be of much use to many people, but I had a need to convert the returned SHA-1 string from here to the underlying raw bytes, hence this... NB. Hex string is assumed NOT to be prefixed with "$" (just because I'm getting hex values from outside of Blitz), so strip that off if needed. Also, note that there's no error checking here to make sure the hex string contains valid characters! | |||||
Function HexToByteArray:Byte [] (hx:String) Local bytes:Byte [Len (hx) / 2] For Local loop:Int = 1 To Len (hx) Step 2 bytes [loop / 2] = Byte ("$" + Mid (hx, loop, 2)) Next Return bytes End Function |
Comments
None.
Code Archives Forum