bbd_lib

Function encode_bcd

Source
pub fn encode_bcd(decimal: u8) -> char
Expand description

Translate a u8 to binary representation using the bcd encoding

bcd: binary coded decimal

TensOnes
n/a8
644
322
161
use bbd_lib::*;

assert_eq!(
    (0..=99).map(|x| encode_bcd(x)).collect::<String>(),
    "\
        ⠀⢀⠠⢠⠐⢐⠰⢰⠈⢈⡀⣀⡠⣠⡐⣐⡰⣰⡈⣈⠄⢄⠤⢤⠔⢔⠴⢴⠌⢌⡄⣄⡤⣤⡔⣔⡴⣴⡌⣌⠂⢂⠢⢢⠒⢒⠲⢲⠊⢊\
        ⡂⣂⡢⣢⡒⣒⡲⣲⡊⣊⠆⢆⠦⢦⠖⢖⠶⢶⠎⢎⡆⣆⡦⣦⡖⣖⡶⣶⡎⣎⠁⢁⠡⢡⠑⢑⠱⢱⠉⢉⡁⣁⡡⣡⡑⣑⡱⣱⡉⣉\
    ",
);

// All byte values greater than 99 panic:
assert!(
    (100..=255)
        .all(|x| std::panic::catch_unwind(|| encode_bcd(x)).is_err()),
);