Grey
0.1.0
Simple Grey codes a.k.a. Reflected Binary Codes library.
|
Grey codes or Reflected binary codes are encodings of unsigned integers such that two adjacent values have only 1 bit of difference. Originally designed for electromechanical switches so that the state would transition cleanly from one value to the other without other values being represented in between. More details on Wikipedia.
This is a tiny tiny C99 library that converts unsigned integers of any size from and to Grey codes.
By default, the library will operate on uint64_t
integers for conversions from/to Grey codes. If you prefer using smaller integer (but also limit the domain of the Grey codes and their values), redefine the macro GREY_UINTBITS
to 32, 16 or 8 instead of 64.
You can also check the tst/test.c
file for more examples.
Copy the inc/grey.h
and src/grey.c
files into your existing C project, add them to the source folders and compile. Done.
If you prefer using smaller integers, redefine GREY_UINTBITS
.
This will build all targets:
libgrey.dylib
/libgrey.dll
shared librarylibgreystatic.a
static librarytest_grey
To compile with the optimisation for size, use the -DCMAKE_BUILD_TYPE=MinSizeRel
flag instead.
If you prefer using smaller integers, set -DGREY_UINTBITS=32
(or 16 or 8).