Function radix50::pdp10::encode_word

source ·
pub fn encode_word(s: &str) -> Result<u32, Error>
Expand description

Encode 6 characters into a PDP-10 RADIX-50 formatted word.

If the string is shorter than 6 characters then the missing characters are assumed to be spaces.

The output is a single 32-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 pdp10_encoded = encode_word("ABCDEF").unwrap();
assert_eq!(pdp10_encoded, 1157975016);

assert_eq!(encode_word("AAAAA").unwrap(), encode_word("AAAAA ").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 }))