heh
Diffstat (limited to 'src/util.rs')
| -rw-r--r-- | src/util.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/util.rs b/src/util.rs index 874ab5a..d7b44a0 100644 --- a/src/util.rs +++ b/src/util.rs @@ -679,9 +679,30 @@ pub mod 読む { } } } + const DIG: [u8; 256] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; pub fn hex_dig(b: u8) -> u8 { - (b & 0xF) + 9 * (b >> 6) + DIG[b.nat()] + // (b & 0xF) + 9 * (b >> 6) + } + + // i wonder if this is genericable + pub fn hex5([a, b, c, d, e]: [u8; 5]) -> u32 { + (hex_dig(a).widen().widen() << 16) + | (hex_dig(b).widen().widen() << 12) + | (hex_dig(c).widen().widen() << 8) + | (hex_dig(d).widen().widen() << 4) + | (hex_dig(e).widen().widen()) } pub fn hex(mut d: &[u8]) -> Result<u32, ()> { |