Skip to content

Instantly share code, notes, and snippets.

Created December 12, 2017 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/c6988d067a72706a0cef25486a302b32 to your computer and use it in GitHub Desktop.
Save anonymous/c6988d067a72706a0cef25486a302b32 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
use std::str;
fn main() {
let b = "67e5504410b1426f9247bb680e5fe0c8";
let mut i = 0;
let mut bytes = [0u8; 16];
for chunk in b.as_bytes().chunks(2) {
let s = match str::from_utf8(chunk) {
Ok(v) => v,
Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
};
match u8::from_str_radix(s, 16) {
Ok(byte) => bytes[i] = byte,
Err(..) => {},
}
i+= 1;
}
println!("{:?}", bytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment