James Kuszmaul | 82f6c04 | 2021-01-17 11:30:16 -0800 | [diff] [blame^] | 1 | /** |
| 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 | */ |
| 17 | uint8_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 | } |