Function radix50::pdp10::encode

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

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

The input string will be space padded to a multiple of 6 characters before encoding. This is because RADIX-50 encodes 6 charaters into a single 32 bit word (36 bits on a PDP-10, but the 4 top bits are unused).

The output is a std::vec::Vec of 32-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 pdp10_encoded = encode("THIS IS A TEST").unwrap();
assert_eq!(pdp10_encoded, [3119342419, 2970305215, 3046400000]);

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

assert_eq!(encode("PADDING12345").unwrap(), encode("PADDING12345").unwrap());
assert_eq!(encode("PADDING123").unwrap(),   encode("PADDING123  ").unwrap());
assert_eq!(encode("PADDING").unwrap(),      encode("PADDING     ").unwrap());