Skip to content

Instantly share code, notes, and snippets.

@squiidz
Forked from anonymous/playground.rs
Created January 27, 2017 19:52
Show Gist options
  • Save squiidz/89efe87a38d18aa54a8da89f4d8bac10 to your computer and use it in GitHub Desktop.
Save squiidz/89efe87a38d18aa54a8da89f4d8bac10 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