The friendly Operating System for the Internet of Things
bitarithm.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef BITARITHM_H
21 #define BITARITHM_H
22 
23 #ifdef __cplusplus
24  extern "C" {
25 #endif
26 
36 #define SETBIT(val, bit) val |= (bit)
37 
47 #define CLRBIT(val, bit) val &= (~(bit))
48 
53 #ifndef BIT0
54 #define BIT0 0x00000001
55 #define BIT1 0x00000002
56 #define BIT2 0x00000004
57 #define BIT3 0x00000008
58 #define BIT4 0x00000010
59 #define BIT5 0x00000020
60 #define BIT6 0x00000040
61 #define BIT7 0x00000080
62 #define BIT8 0x00000100
63 #define BIT9 0x00000200
64 #define BIT10 0x00000400
65 #define BIT11 0x00000800
66 #define BIT12 0x00001000
67 #define BIT13 0x00002000
68 #define BIT14 0x00004000
69 #define BIT15 0x00008000
70 #endif
71 #ifndef BIT16
72 #define BIT16 0x00010000
73 #define BIT17 0x00020000
74 #define BIT18 0x00040000
75 #define BIT19 0x00080000
76 #define BIT20 0x00100000
77 #define BIT21 0x00200000
78 #define BIT22 0x00400000
79 #define BIT23 0x00800000
80 #define BIT24 0x01000000
81 #define BIT25 0x02000000
82 #define BIT26 0x04000000
83 #define BIT27 0x08000000
84 #define BIT28 0x10000000
85 #define BIT29 0x20000000
86 #define BIT30 0x40000000
87 #define BIT31 0x80000000
88 #endif
89 
91 #define ARCH_32_BIT (__INT_MAX__ == 2147483647)
100 unsigned bitarithm_msb(unsigned v);
101 
110 unsigned bitarithm_lsb(register unsigned v);
111 
119 unsigned bitarithm_bits_set(unsigned v);
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif /* BITARITHM_H */
126 
unsigned bitarithm_lsb(register unsigned v)
Returns the number of the lowest '1' bit in a value.
unsigned bitarithm_bits_set(unsigned v)
Returns the number of bits set in a value.