#include <stdio.h>
#include <stdint.h>

static inline uint8_t rev8(uint8_t d)
{
    int i;
    uint8_t out = 0;

    /* (from left to right) */
    for (i = 0; i < 8; i++)
        if (d & (1 << i))
            out |= (1 << (7 - i));

    return out;
}

/* http://www.onsemi.com/pub_link/Collateral/ADP3208D.PDF */
static inline uint32_t encode_voltage(uint32_t v)
{
	return rev8((0x78 - v / 125) << 1 | 1) << 8;
}

static inline uint32_t decode_voltage(uint32_t v)
{
	return (0x78 - (rev8(v >> 8) >> 1)) * 125;
}

int main()
{
	int v = 0;
	while (v < 15000) {
		printf("%d --> %04x | %d\n", v, encode_voltage(v), encode_voltage(v));
		v += 125;
	}
}

Add a simple voltage encode/decode c code
Add a simple voltage encode/decode c code
