9ed432fbd50698dd34938e87e501c0e5cce6b243
nibbles
A toy C library that converts numbers to and from BCD. I suggest you don't use it.
Named after half a byte.
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:
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!
Have fun!
Description
Languages
C
99.8%
Makefile
0.2%