libcoap  4.1.2
bits.h
Go to the documentation of this file.
1 /*
2  * bits.h -- bit vector manipulation
3  *
4  * Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
15 #ifndef _COAP_BITS_H_
16 #define _COAP_BITS_H_
17 
18 #include <stdint.h>
19 
31 inline static int
32 bits_setb(uint8_t *vec, size_t size, uint8_t bit) {
33  if (size <= (bit >> 3))
34  return -1;
35 
36  *(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07));
37  return 1;
38 }
39 
51 inline static int
52 bits_clrb(uint8_t *vec, size_t size, uint8_t bit) {
53  if (size <= (bit >> 3))
54  return -1;
55 
56  *(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07)));
57  return 1;
58 }
59 
70 inline static int
71 bits_getb(const uint8_t *vec, size_t size, uint8_t bit) {
72  if (size <= (bit >> 3))
73  return -1;
74 
75  return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0;
76 }
77 
78 #endif /* _COAP_BITS_H_ */
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
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
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