Unpack hot 2-bpw format back to `i8` trits.
(hot: &[u8], dim: usize)
| 79 | |
| 80 | /// Unpack hot 2-bpw format back to `i8` trits. |
| 81 | pub fn unpack_hot(hot: &[u8], dim: usize) -> Vec<i8> { |
| 82 | let mut out = Vec::with_capacity(dim); |
| 83 | 'outer: for &byte in hot { |
| 84 | for slot in 0..4 { |
| 85 | if out.len() >= dim { |
| 86 | break 'outer; |
| 87 | } |
| 88 | let bits = (byte >> (slot * 2)) & 0b11; |
| 89 | out.push(match bits { |
| 90 | 0b00 => -1, |
| 91 | 0b10 => 1, |
| 92 | _ => 0, |
| 93 | }); |
| 94 | } |
| 95 | } |
| 96 | out |
| 97 | } |
| 98 | |
| 99 | /// Convert cold-packed trits to hot-packed trits. |
| 100 | pub fn cold_to_hot(cold: &[u8], dim: usize) -> Vec<u8> { |
no test coverage detected