Function radix50::pdp11::encode

source ·
pub fn encode(s: &str) -> Result<Vec<u16>, Error>
Expand description

Encode a string into PDP-11 RADIX-50 format.

The input string will be space padded to a multiple of 3 characters before encoding. This is because RADIX-50 encodes 3 charaters into a single 16 bit word.

The output is a std::vec::Vec of 16-bit words.

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("THIS IS A TEST").unwrap();
assert_eq!(pdp11_encoded, [32329, 30409, 30401, 805, 31200]);

let result = encode("This contains invalid characters");
assert_eq!(result, Err(Error::IllegalChar { char: 'h', pos: 2 }));

assert_eq!(encode("PADDING12").unwrap(), encode("PADDING12").unwrap());
assert_eq!(encode("PADDING1").unwrap(),  encode("PADDING1 ").unwrap());
assert_eq!(encode("PADDING").unwrap(),   encode("PADDING  ").unwrap());