-
-
Save squiidz/89efe87a38d18aa54a8da89f4d8bac10 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or 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
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