Created
December 12, 2017 07:54
-
-
Save anonymous/c6988d067a72706a0cef25486a302b32 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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