Function utils::md5::to_hex

source ·
pub fn to_hex([a, b, c, d]: [u32; 4]) -> [u8; 32]
Expand description

Convert an MD5 hash to ASCII hex.

Implemented using bitwise operations on each u32 to spread each nibble into separate bytes, followed by adding either ‘0’ or ‘a’ to each byte using a bitmask.

When using the vectorized AVX2 MD5 implementation, this makes 2016 day 14 roughly 4x faster compared to using a naive format! implementation format!("{a:08x}{b:08x}{c:08x}{d:08x}").

§Examples

assert_eq!(
    to_hex([0xd41d8cd9, 0x8f00b204, 0xe9800998, 0xecf8427e]),
    *b"d41d8cd98f00b204e9800998ecf8427e",
);