flm01/mote/v2/avr/encode.h

19 lines
621 B
C
Raw Normal View History

2011-01-15 22:30:59 +00:00
#include <stdint.h>
// hex to binary/byte decoding
static inline void htob(uint8_t high_hex, uint8_t low_hex, uint8_t *pbyte)
2011-01-15 22:30:59 +00:00
{
*pbyte = (high_hex > 0x40) ? (high_hex & 0x0F) + 9 : high_hex & 0x0F;
*pbyte = *pbyte << 4;
*pbyte |= (low_hex > 0x40) ? (low_hex & 0x0F) + 9 : low_hex & 0x0F;
2011-01-15 22:30:59 +00:00
}
// binary/byte to hex encoding
static inline void btoh(uint8_t byte, uint8_t *phigh_hex, uint8_t *plow_hex)
2011-01-15 22:30:59 +00:00
{
*plow_hex = byte & 0x0F;
*plow_hex = (*plow_hex > 0x09) ? *plow_hex - 9 + 0x60 : *plow_hex + 0x30;
*phigh_hex = (byte & 0xF0) >> 4;
*phigh_hex = (*phigh_hex > 0x09) ? *phigh_hex - 9 + 0x60 : *phigh_hex + 0x30;
2011-01-15 22:30:59 +00:00
}