Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2017 19:44
Show Gist options
  • Save anonymous/273bafca851848e44489c96c2ea85b0b to your computer and use it in GitHub Desktop.
Save anonymous/273bafca851848e44489c96c2ea85b0b to your computer and use it in GitHub Desktop.
Shared via Rust Playground
fn main() {
let text = "ありがとうございます";
let words = text.split("").map(|w| w.as_bytes()).collect::<Vec<&[u8]>>();
let length = words.iter().fold(0, |acc, val| acc + val.len());
println!("Input Text: {}", text);
println!("Bytes: {:?}", words);
println!("Text is {} bytes long", length);
let mut inline_bits = String::new();
let mut index = 0;
for bytes in words {
for b in bytes {
println!("{} => {:?} => {:X} => {:b}", text.chars().nth(index).unwrap(), b, b, b);
inline_bits.push_str(&format!("{:b} ", b));
index += 1;
}
}
println!("Inline => {}", inline_bits)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment