blob: 24c40170c216efe0ae799b5b22817368174488f6 [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file ch.c Character format functions
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6#include <re_types.h>
7#include <re_fmt.h>
8
9
10/**
11 * Convert an ASCII hex character to binary format
12 *
13 * @param ch ASCII hex character
14 *
15 * @return Binary value
16 */
17uint8_t ch_hex(char ch)
18{
19 if ('0' <= ch && ch <= '9')
20 return ch - '0';
21
22 else if ('A' <= ch && ch <= 'F')
23 return ch - 'A' + 10;
24
25 else if ('a' <= ch && ch <= 'f')
26 return ch - 'a' + 10;
27
28 return 0;
29}