FastArduino  v1.8
C++ library to build fast but small Arduino/AVR projects
bits Namespace Reference

Defines utility methods for bits manipulation. More...

Functions

static constexpr uint8_t BV8 (uint8_t bit)
 Create a uint8_t bitmask for the given bit number. More...
 
static constexpr uint8_t BV8 (uint8_t bit1, uint8_t bit2)
 Create a uint8_t bitmask for the given bits numbers. More...
 
static constexpr uint8_t BV8 (uint8_t bit1, uint8_t bit2, uint8_t bit3)
 Create a uint8_t bitmask for the given bits numbers. More...
 
static constexpr uint8_t BV8 (uint8_t bit1, uint8_t bit2, uint8_t bit3, uint8_t bit4)
 Create a uint8_t bitmask for the given bits numbers. More...
 
static constexpr uint8_t BV8 (uint8_t bit1, uint8_t bit2, uint8_t bit3, uint8_t bit4, uint8_t bit5)
 Create a uint8_t bitmask for the given bits numbers. More...
 
static constexpr uint8_t BV8 (uint8_t bit1, uint8_t bit2, uint8_t bit3, uint8_t bit4, uint8_t bit5, uint8_t bit6)
 Create a uint8_t bitmask for the given bits numbers. More...
 
static constexpr uint8_t CBV8 (uint8_t bit)
 Create a uint8_t inverted bitmask for the given bit number. More...
 
static constexpr uint16_t BV16 (uint8_t bit)
 Create a uint16_t bitmask for the given bit number. More...
 
static constexpr uint16_t BV16 (uint8_t bit1, uint8_t bit2)
 Create a uint16_t bitmask for the given bits numbers. More...
 
static constexpr uint16_t BV16 (uint8_t bit1, uint8_t bit2, uint8_t bit3)
 Create a uint16_t bitmask for the given bits numbers. More...
 
static constexpr uint16_t BV16 (uint8_t bit1, uint8_t bit2, uint8_t bit3, uint8_t bit4)
 Create a uint16_t bitmask for the given bits numbers. More...
 
static constexpr uint16_t BV16 (uint8_t bit1, uint8_t bit2, uint8_t bit3, uint8_t bit4, uint8_t bit5)
 Create a uint16_t bitmask for the given bits numbers. More...
 
static constexpr uint16_t BV16 (uint8_t bit1, uint8_t bit2, uint8_t bit3, uint8_t bit4, uint8_t bit5, uint8_t bit6)
 Create a uint16_t bitmask for the given bits numbers. More...
 
static constexpr uint16_t CBV16 (uint8_t bit)
 Create a uint16_t inverted bitmask for the given bit number. More...
 
static constexpr uint8_t COMPL (uint8_t value)
 Return the uint8_t 2-complement of a byte. More...
 
static constexpr uint8_t LOW_BYTE (uint16_t value)
 Extract the low byte (aka Least Significant Byte, LSB) of a uint16_t value.
 
static constexpr uint8_t HIGH_BYTE (uint16_t value)
 Extract the high byte (aka Most Significant Byte, MSB) of a uint16_t value.
 

Detailed Description

Defines utility methods for bits manipulation.

Most functions defined here are constexpr, which means that they can be evaluated at compile-time when constant arguments. These functions are used to ensure proper casting of results to the required types, i.e. uint8_t or uint16_t.

Function Documentation

◆ BV8() [1/6]

static constexpr uint8_t bits::BV8 ( uint8_t  bit)
staticconstexpr

Create a uint8_t bitmask for the given bit number.

Concretely, this is simply the 1 << bit expression.

Parameters
bitthe bit number for which to produce a bitmask, should be between 0 and 7.

Definition at line 41 of file bits.h.

◆ BV8() [2/6]

static constexpr uint8_t bits::BV8 ( uint8_t  bit1,
uint8_t  bit2 
)
staticconstexpr

Create a uint8_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) expression.

Parameters
bit1the first bit number for which to produce a bitmask, should be between 0 and 7.
bit2the second bit number for which to produce a bitmask, should be between 0 and 7.

Definition at line 54 of file bits.h.

◆ BV8() [3/6]

static constexpr uint8_t bits::BV8 ( uint8_t  bit1,
uint8_t  bit2,
uint8_t  bit3 
)
staticconstexpr

Create a uint8_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) ... expression.

Parameters
bit1the first bit number for which to produce a bitmask, should be between 0 and 7.
bit2the second bit number for which to produce a bitmask, should be between 0 and 7.
bit3the third bit number for which to produce a bitmask, should be between 0 and 7.

Definition at line 69 of file bits.h.

◆ BV8() [4/6]

static constexpr uint8_t bits::BV8 ( uint8_t  bit1,
uint8_t  bit2,
uint8_t  bit3,
uint8_t  bit4 
)
staticconstexpr

Create a uint8_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) ... expression.

Parameters
bit1the first bit number for which to produce a bitmask, should be between 0 and 7.
bit2the second bit number for which to produce a bitmask, should be between 0 and 7.
bit3the third bit number for which to produce a bitmask, should be between 0 and 7.
bit4the fourth bit number for which to produce a bitmask, should be between 0 and 7.

Definition at line 86 of file bits.h.

◆ BV8() [5/6]

static constexpr uint8_t bits::BV8 ( uint8_t  bit1,
uint8_t  bit2,
uint8_t  bit3,
uint8_t  bit4,
uint8_t  bit5 
)
staticconstexpr

Create a uint8_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) ... expression.

Parameters
bit1the first bit number for which to produce a bitmask, should be between 0 and 7.
bit2the second bit number for which to produce a bitmask, should be between 0 and 7.
bit3the third bit number for which to produce a bitmask, should be between 0 and 7.
bit4the fourth bit number for which to produce a bitmask, should be between 0 and 7.
bit5the fifth bit number for which to produce a bitmask, should be between 0 and 7.

Definition at line 105 of file bits.h.

◆ BV8() [6/6]

static constexpr uint8_t bits::BV8 ( uint8_t  bit1,
uint8_t  bit2,
uint8_t  bit3,
uint8_t  bit4,
uint8_t  bit5,
uint8_t  bit6 
)
staticconstexpr

Create a uint8_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) ... expression.

Parameters
bit1the first bit number for which to produce a bitmask, should be between 0 and 7.
bit2the second bit number for which to produce a bitmask, should be between 0 and 7.
bit3the third bit number for which to produce a bitmask, should be between 0 and 7.
bit4the fourth bit number for which to produce a bitmask, should be between 0 and 7.
bit5the fifth bit number for which to produce a bitmask, should be between 0 and 7.
bit6the sixth bit number for which to produce a bitmask, should be between 0 and 7.

Definition at line 126 of file bits.h.

◆ CBV8()

static constexpr uint8_t bits::CBV8 ( uint8_t  bit)
staticconstexpr

Create a uint8_t inverted bitmask for the given bit number.

Concretely, this is simply the ~(1 << bit) expression.

Parameters
bitthe bit number for which to produce a bitmask, should be between 0 and 7.

Definition at line 137 of file bits.h.

◆ BV16() [1/6]

static constexpr uint16_t bits::BV16 ( uint8_t  bit)
staticconstexpr

Create a uint16_t bitmask for the given bit number.

Concretely, this is simply the 1 << bit expression.

Parameters
bitthe bit number for which to produce a bitmask, should be between 0 and 15.

Definition at line 148 of file bits.h.

◆ BV16() [2/6]

static constexpr uint16_t bits::BV16 ( uint8_t  bit1,
uint8_t  bit2 
)
staticconstexpr

Create a uint16_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) expression.

Parameters
bit1the bit number for which to produce a bitmask, should be between 0 and 15.
bit2the bit number for which to produce a bitmask, should be between 0 and 15.

Definition at line 161 of file bits.h.

◆ BV16() [3/6]

static constexpr uint16_t bits::BV16 ( uint8_t  bit1,
uint8_t  bit2,
uint8_t  bit3 
)
staticconstexpr

Create a uint16_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) ... expression.

Parameters
bit1the bit number for which to produce a bitmask, should be between 0 and 15.
bit2the bit number for which to produce a bitmask, should be between 0 and 15.
bit3the bit number for which to produce a bitmask, should be between 0 and 15.

Definition at line 176 of file bits.h.

◆ BV16() [4/6]

static constexpr uint16_t bits::BV16 ( uint8_t  bit1,
uint8_t  bit2,
uint8_t  bit3,
uint8_t  bit4 
)
staticconstexpr

Create a uint16_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) ... expression.

Parameters
bit1the bit number for which to produce a bitmask, should be between 0 and 15.
bit2the bit number for which to produce a bitmask, should be between 0 and 15.
bit3the bit number for which to produce a bitmask, should be between 0 and 15.
bit4the bit number for which to produce a bitmask, should be between 0 and 15.

Definition at line 193 of file bits.h.

◆ BV16() [5/6]

static constexpr uint16_t bits::BV16 ( uint8_t  bit1,
uint8_t  bit2,
uint8_t  bit3,
uint8_t  bit4,
uint8_t  bit5 
)
staticconstexpr

Create a uint16_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) ... expression.

Parameters
bit1the bit number for which to produce a bitmask, should be between 0 and 15.
bit2the bit number for which to produce a bitmask, should be between 0 and 15.
bit3the bit number for which to produce a bitmask, should be between 0 and 15.
bit4the bit number for which to produce a bitmask, should be between 0 and 15.
bit5the bit number for which to produce a bitmask, should be between 0 and 15.

Definition at line 212 of file bits.h.

◆ BV16() [6/6]

static constexpr uint16_t bits::BV16 ( uint8_t  bit1,
uint8_t  bit2,
uint8_t  bit3,
uint8_t  bit4,
uint8_t  bit5,
uint8_t  bit6 
)
staticconstexpr

Create a uint16_t bitmask for the given bits numbers.

Concretely, this is simply the (1 << bit1) | (1 << bit2) ... expression.

Parameters
bit1the bit number for which to produce a bitmask, should be between 0 and 15.
bit2the bit number for which to produce a bitmask, should be between 0 and 15.
bit3the bit number for which to produce a bitmask, should be between 0 and 15.
bit4the bit number for which to produce a bitmask, should be between 0 and 15.
bit5the bit number for which to produce a bitmask, should be between 0 and 15.
bit6the bit number for which to produce a bitmask, should be between 0 and 15.

Definition at line 233 of file bits.h.

◆ CBV16()

static constexpr uint16_t bits::CBV16 ( uint8_t  bit)
staticconstexpr

Create a uint16_t inverted bitmask for the given bit number.

Concretely, this is simply the ~(1 << bit) expression.

Parameters
bitthe bit number for which to produce a bitmask, should be between 0 and 15.

Definition at line 244 of file bits.h.

◆ COMPL()

static constexpr uint8_t bits::COMPL ( uint8_t  value)
staticconstexpr

Return the uint8_t 2-complement of a byte.

Concretely, this is simply the ~value expression.

Definition at line 253 of file bits.h.