libcoap  4.1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
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
7  * README for terms of use.
8  */
9 
15 #ifndef _BITS_H_
16 #define _BITS_H_
17 
18 #include <sys/types.h>
19 #include <stdint.h>
20 
32 inline static int
33 bits_setb(uint8_t *vec, size_t size, uint8_t bit) {
34  if (size <= (bit >> 3))
35  return -1;
36 
37  *(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07));
38  return 1;
39 }
40 
52 inline static int
53 bits_clrb(uint8_t *vec, size_t size, uint8_t bit) {
54  if (size <= (bit >> 3))
55  return -1;
56 
57  *(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07)));
58  return 1;
59 }
60 
71 inline static int
72 bits_getb(const uint8_t *vec, size_t size, uint8_t bit) {
73  if (size <= (bit >> 3))
74  return -1;
75 
76  return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0;
77 }
78 
79 #endif /* _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:33
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:72
static int bits_clrb(uint8_t *vec, size_t size, uint8_t bit)
Clears the bit bit from bit-vector vec.
Definition: bits.h:53