bits.h
Go to the documentation of this file.
/*
* bits.h -- bit vector manipulation
*
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef _COAP_BITS_H_
#define _COAP_BITS_H_
#include <stdint.h>
inline static int
bits_setb(uint8_t *vec, size_t size, uint8_t bit) {
if (size <= (bit >> 3))
return -1;
*(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07));
return 1;
}
inline static int
bits_clrb(uint8_t *vec, size_t size, uint8_t bit) {
if (size <= (bit >> 3))
return -1;
*(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07)));
return 1;
}
inline static int
bits_getb(const uint8_t *vec, size_t size, uint8_t bit) {
if (size <= (bit >> 3))
return -1;
return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0;
}
#endif /* _COAP_BITS_H_ */
bits_setb
static int bits_setb(uint8_t *vec, size_t size, uint8_t bit)
Sets the bit bit in bit-vector vec.
Definition: bits.h:32
bits_getb
static int bits_getb(const uint8_t *vec, size_t size, uint8_t bit)
Gets the status of bit bit from bit-vector vec.
Definition: bits.h:71
bits_clrb
static int bits_clrb(uint8_t *vec, size_t size, uint8_t bit)
Clears the bit bit from bit-vector vec.
Definition: bits.h:52