How to convert text to binary code in Rust

1 Answer

0 votes
fn text2bin(txt: &str) -> String {
    txt.chars()
        .map(|ch| format!("{:08b} ", ch as u8))
        .collect::<String>()
}

fn main() {
    println!("{}", text2bin("Rust Programming"));
}


 
 
/*
run:
 
01010010 01110101 01110011 01110100 00100000 01010000 01110010 01101111 01100111 01110010 01100001 01101101 01101101 01101001 01101110 01100111 
 
*/

 



answered Nov 18, 2024 by avibootz

Related questions

1 answer 114 views
2 answers 138 views
1 answer 178 views
178 views asked Oct 2, 2022 by avibootz
1 answer 212 views
1 answer 97 views
1 answer 79 views
...