code_junkie

f# byte[] -> hex -> string conversion

Nov 13th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. let ByteToHex bytes =
  2. bytes
  3. |> Array.map (fun (x : byte) -> String.Format("{0:X2}", x))
  4.  
  5. let ConcatArray stringArray = String.Join(null, (ByteToHex stringArray))
  6.  
  7. let ByteToHex bytes =
  8. bytes
  9. |> Array.map (fun (x : byte) -> System.String.Format("{0:X2}", x))
  10. |> String.concat System.String.Empty
  11.  
  12. val ksprintf : (string -> 'd) -> StringFormat<'a,'d> -> 'a
  13. sprintf, but call the given 'final' function to generate the result.
  14.  
  15. StringBuilder sb = new StringBuilder();
  16. foreach (byte b in raw) {
  17. sb.Append(b.ToString("x2"));
  18. }
  19. return sb.ToString()
Add Comment
Please, Sign In to add comment