Function bbd_lib::encode_bcd
source · pub fn encode_bcd(decimal: u8) -> charExpand description
Translate a u8 to binary representation using the bcd encoding
bcd: binary coded decimal
| Tens | Ones |
|---|---|
| n/a | 8 |
| 64 | 4 |
| 32 | 2 |
| 16 | 1 |
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()),
);