This commit is contained in:
2017-07-24 17:13:16 -04:00
commit ac42f6e84a
6 changed files with 1276 additions and 0 deletions

34
README.md Normal file
View File

@@ -0,0 +1,34 @@
# nibbles
A toy C library that converts numbers to and from [BCD](https://en.wikipedia.org/wiki/Binary-coded_decimal).
I suggest you don't use it.
## Installation
Don't. The makefile only includes a test target, because I want to test my code.
## Usage
The library knows how to convert `uint<n>_t` types into BCD. It also knows
how to convert them back into `uint64_t`—only that because any other
representation might lead to a loss of information. It can also convert from
BCD to strings. The functions are:
```c
bcd bcd_zeros(); // creates a BCD of value 0
bcd bcd_from_8(uint8_t); // creates a BCD from a byte
bcd bcd_from_16(uint16_t); // creates a BCD from 2 bytes
bcd bcd_from_32(uint32_t); // and so on
bcd bcd_from_64(uint64_t); // ..
uint8_t bcd_digits(bcd); // gets the number of digits in the BCD
uint64_t bcd_to_64(bcd); // converts a BCD to a 8 bytes (64 bit) number
char* bcd_to_string(bcd); // converts a BCD to a string (memory is now yours)
```
That's it!
<hr/>
Have fun!