diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-11-21 20:05:55 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-11-21 20:05:55 +0100 |
commit | 1c3cb6b233ef0ae82d4178d78817e43ecce0da4b (patch) | |
tree | f2031743139bd0bfd9f8d5c3f11a07b375706e50 | |
parent | 927cc35bb845a48151951c3284ba9d3ec59d8130 (diff) | |
download | etisnoop-1c3cb6b233ef0ae82d4178d78817e43ecce0da4b.tar.gz etisnoop-1c3cb6b233ef0ae82d4178d78817e43ecce0da4b.tar.bz2 etisnoop-1c3cb6b233ef0ae82d4178d78817e43ecce0da4b.zip |
Add utils.h
-rw-r--r-- | utils.h | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -0,0 +1,32 @@ +#include <stdlib.h> +#include <stdint.h> + +#ifndef __UTILS_H_ +#define __UTILS_H_ +static inline +void setBit(uint8_t x [], uint8_t bit, int32_t pos) +{ + int16_t iByte; + int16_t iBit; + + iByte = pos / 8; + iBit = pos % 8; + x[iByte] = (x[iByte] & (~(1 << (7 - iBit)))) | + (bit << (7 - iBit)); +} + +static inline +void setBits(uint8_t x[], uint32_t bits, + int32_t startPosition, int32_t numBits) +{ + int32_t i; + uint8_t bit; + + for (i = 0; i < numBits; i ++) { + bit = bits & (1 << (numBits - i - 1)) ? 1 : 0; + setBit(x, bit, startPosition + i); + } +} + +#endif + |