comparison libnumutil/digit_groups.c @ 0:159dd90eeafe

beginning, libnumutil compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 12 Dec 2023 23:52:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:159dd90eeafe
1 /*
2 * In version 2 of ThemWi owned number database, NANP numbers are stored as 3
3 * uint16_t words: NPA, exchange and prefix, each uint16_t encoding a group of
4 * 3 or 4 digits of the full telephone number. This library module provides
5 * functions for turning groups of 3 or 4 digits into uint16_t words.
6 */
7
8 #include <stdint.h>
9
10 #include <themwi/nanp/number_utils.h>
11
12 uint16_t digits3_to_uint16(const char *str)
13 {
14 int acc;
15
16 acc = (str[0] - '0') * 100;
17 acc += (str[1] - '0') * 10;
18 acc += str[2] - '0';
19 return acc;
20 }
21
22 uint16_t digits4_to_uint16(const char *str)
23 {
24 int acc;
25
26 acc = (str[0] - '0') * 1000;
27 acc += (str[1] - '0') * 100;
28 acc += (str[2] - '0') * 10;
29 acc += str[3] - '0';
30 return acc;
31 }