Function radix50::pdp11::encode_word
source · pub fn encode_word(s: &str) -> Result<u16, Error>
Expand description
Encode 3 characters into a PDP-11 RADIX-50 formatted word.
If the string is shorter than 3 characters then the missing characters are assumed to be spaces.
The output is a single 16-bit word.
It will return an Error if any of the input characters are not part of the valid RADIX-50 character set.
§Examples
let pdp11_encoded = encode_word("ABC").unwrap();
assert_eq!(pdp11_encoded, 1683);
assert_eq!(encode_word("AA").unwrap(), encode_word("AA ").unwrap());
assert_eq!(encode_word("A").unwrap(), encode_word("A ").unwrap());
assert_eq!(encode_word("").unwrap(), encode_word(" ").unwrap());
let result = encode_word("AB-");
assert_eq!(result, Err(Error::IllegalChar { char: '-', pos: 3 }))