aboutsummaryrefslogtreecommitdiffstats
path: root/utils.h
blob: 9c43c881a55ec138e521089e80cf287b8421fdbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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