I'm trying to convert a String which contains the binary representation of some ASCII text, back to the ASCII text.
I have the following &str:
let binary: &str = "01010010 01110101 01110011 01110100 01100001 01100011 01100101 01100001 01101110 01110011";
And I want to convert this &str to the ASCII version, which is the word: "Rustaceans".
Currently I'm converting this word to binary as follows:
fn to_binary(s: &str) -> String {
let mut binary = String::default();
let ascii: String = s.into();
for character in ascii.clone().into_bytes() {
binary += &format!("0{:b} ", character);
}
// removes the trailing space at the end
binary.pop();
binary
}
I'm looking for the function which will take the output of to_binary and returns "Rustaceans".
Thanks in advance!