Closed subversive-owl closed 6 years ago
terrible implementation to be constructive:
fn reverse_endianness(in_str: &str) -> String {
let mut rev_str = "".to_string();
for chunk in in_str.chars().collect::<Vec<char>>().chunks(4) {
// hardcoding this because, ugh, seriously
let swapped_chars: Vec<char> = vec![chunk[2],
chunk[3],
chunk[0],
chunk[1]];
rev_str.push_str(String::from_iter(swapped_chars).as_str());
}
rev_str
}```
Closing this issue as hex
is only meant to convert bytes into its hexadecimal form, while handling endianness is only needed when handling integers... Plus it would require to handle different integer sizes, which would only lead to overcomplex code for the library's scope.
As an alternative, you can actually manipulate the bytes directly to reverse stuff if you really need to.
(I should have closed it sooner, sorry...)
it's relatively minor, but the endianness of the output of
.to_hex()
may differ from the output of POSIXhexdump
:hexdump:
to_hex
:"217c1f6c2c6b4c27c39eb455df48fd86dbed9161f47373b0c91e122d4c310ba8"
Being able to choose would be a nice feature.