Skip to main content

parse_nibble

Function parse_nibble 

Source
pub const fn parse_nibble(b: u8) -> Option<u8>
Expand description

Safely parses a hex character into a nibble (0-15).

Returns None for invalid hex characters.

ยงExamples

use omp_core::hex::parse_nibble;
assert_eq!(parse_nibble(b'A'), Some(10));
assert_eq!(parse_nibble(b'f'), Some(15));
assert_eq!(parse_nibble(b'0'), Some(0));
assert_eq!(parse_nibble(b'g'), None);