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>
COAP_STATIC_INLINE int
bits_setb(uint8_t *vec, size_t size, uint8_t bit) {
if (size <= ((size_t)bit >> 3))
return -1;
*(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07));
return 1;
}
COAP_STATIC_INLINE int
bits_clrb(uint8_t *vec, size_t size, uint8_t bit) {
if (size <= ((size_t)bit >> 3))
return -1;
*(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07)));
return 1;
}
COAP_STATIC_INLINE int
bits_getb(const uint8_t *vec, size_t size, uint8_t bit) {
if (size <= ((size_t)bit >> 3))
return -1;
return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0;
}
#endif /* COAP_BITS_H_ */
bits_clrb
COAP_STATIC_INLINE int bits_clrb(uint8_t *vec, size_t size, uint8_t bit)
Clears the bit bit from bit-vector vec.
Definition: bits.h:52
COAP_STATIC_INLINE
#define COAP_STATIC_INLINE
Definition: libcoap.h:38
bits_setb
COAP_STATIC_INLINE 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
COAP_STATIC_INLINE 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
uint8_t
unsigned char uint8_t
Definition: uthash.h:79