I have an array of bytes as input. I would like to convert this array to a string containing a hexadecimal representation of the values of the array. This is the F # code:
let ByteToHex bytes =
bytes
|> Array.map (fun (x : byte) -> String.Format("{0:X2}", x))
let ConcatArray stringArray = String.Join(null, (ByteToHex stringArray))
This gives the result that I need, but I would like to make it more compact so that I have only one function. I could not find a function that would execute a string representation of each byte at the end of ByteToHex.
I tried Array.concat, concat_map, I tried with lists, but the best I could get was an array or list of strings.
Questions:
- What would be the easiest, most elegant way to do this?
- Is there a formatting string in F # so that I can replace String.Format from the system assembly?
Input Example: [| 0x24uy; 0xA1uy; 0x00uy; 0x1Cuy |] should create the string "24A1001C"
source
share