FreeCalypso > hg > themwi-nanp
view libnumutil/digit_groups.c @ 13:c0bfd300b6e5
add INSTALL
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 13 Dec 2023 06:07:40 +0000 |
parents | 159dd90eeafe |
children |
line wrap: on
line source
/* * In version 2 of ThemWi owned number database, NANP numbers are stored as 3 * uint16_t words: NPA, exchange and prefix, each uint16_t encoding a group of * 3 or 4 digits of the full telephone number. This library module provides * functions for turning groups of 3 or 4 digits into uint16_t words. */ #include <stdint.h> #include <themwi/nanp/number_utils.h> uint16_t digits3_to_uint16(const char *str) { int acc; acc = (str[0] - '0') * 100; acc += (str[1] - '0') * 10; acc += str[2] - '0'; return acc; } uint16_t digits4_to_uint16(const char *str) { int acc; acc = (str[0] - '0') * 1000; acc += (str[1] - '0') * 100; acc += (str[2] - '0') * 10; acc += str[3] - '0'; return acc; }