Given a hex string, such as "d59c168e05df4757"
, how can I reverse the bytes of this string, so as to read [57, 47, df, 05, 8e, 16, 9c, d5]
?
Using the as_bytes()
method converts each individual character into a byte value, rather than the two-character hex representation.
From bytes representation I have tried the following without success:
let bytes = vec![213, 156, 22, 142, 5, 223, 71, 87];
let bytes_reversed = bytes.iter().rev();
println!("Bytes reversed: {:x?}", bytes_reversed);
//Prints: Bytes reversed: Rev { iter: Iter([d5, 9c, 16, 8e, 5, df, 47, 57]) }