FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
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. More...
 
static constexpr uint8_t HIGH_BYTE (uint16_t value)
 Extract the high byte (aka Most Significant Byte, MSB) of a uint16_t value. More...
 
static constexpr uint8_t OR8 (uint8_t val1, uint8_t val2)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands. More...
 
static constexpr uint8_t OR8 (uint8_t val1, uint8_t val2, uint8_t val3)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands. More...
 
static constexpr uint8_t OR8 (uint8_t val1, uint8_t val2, uint8_t val3, uint8_t val4)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands. More...
 
static constexpr uint8_t OR8 (uint8_t val1, uint8_t val2, uint8_t val3, uint8_t val4, uint8_t val5)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands. More...
 
static constexpr uint8_t OR8 (uint8_t val1, uint8_t val2, uint8_t val3, uint8_t val4, uint8_t val5, uint8_t val6)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands. More...
 
static constexpr uint8_t IF8 (bool flag, uint8_t val)
 return val if flag is true, otherwise 0, as an uint8_t. More...
 
static constexpr uint8_t ORIF8 (bool flag1, uint8_t val1, bool flag2, uint8_t val2)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags. More...
 
static constexpr uint8_t ORIF8 (bool flag1, uint8_t val1, bool flag2, uint8_t val2, bool flag3, uint8_t val3)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags. More...
 
static constexpr uint8_t ORIF8 (bool flag1, uint8_t val1, bool flag2, uint8_t val2, bool flag3, uint8_t val3, bool flag4, uint8_t val4)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags. More...
 
static constexpr uint8_t ORIF8 (bool flag1, uint8_t val1, bool flag2, uint8_t val2, bool flag3, uint8_t val3, bool flag4, uint8_t val4, bool flag5, uint8_t val5)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags. More...
 
static constexpr uint8_t ORIF8 (bool flag1, uint8_t val1, bool flag2, uint8_t val2, bool flag3, uint8_t val3, bool flag4, uint8_t val4, bool flag5, uint8_t val5, bool flag6, uint8_t val6)
 Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags. More...
 

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.

◆ LOW_BYTE()

static constexpr uint8_t bits::LOW_BYTE ( uint16_t  value)
staticconstexpr

Extract the low byte (aka Least Significant Byte, LSB) of a uint16_t value.

Definition at line 261 of file bits.h.

◆ HIGH_BYTE()

static constexpr uint8_t bits::HIGH_BYTE ( uint16_t  value)
staticconstexpr

Extract the high byte (aka Most Significant Byte, MSB) of a uint16_t value.

Definition at line 269 of file bits.h.

◆ OR8() [1/5]

static constexpr uint8_t bits::OR8 ( uint8_t  val1,
uint8_t  val2 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands.

This method exists to ensure proper result cast to uint8_t. Concretely, this is simply the val1 | val2 expression.

Parameters
val1the first byte to be ORed.
val2the second byte to be ORed.

Definition at line 281 of file bits.h.

◆ OR8() [2/5]

static constexpr uint8_t bits::OR8 ( uint8_t  val1,
uint8_t  val2,
uint8_t  val3 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands.

This method exists to ensure proper result cast to uint8_t.

Parameters
val1the first byte to be ORed.
val2the second byte to be ORed.
val3the third byte to be ORed.

Definition at line 293 of file bits.h.

◆ OR8() [3/5]

static constexpr uint8_t bits::OR8 ( uint8_t  val1,
uint8_t  val2,
uint8_t  val3,
uint8_t  val4 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands.

This method exists to ensure proper result cast to uint8_t.

Parameters
val1the first byte to be ORed.
val2the second byte to be ORed.
val3the third byte to be ORed.
val4the third byte to be ORed.

Definition at line 306 of file bits.h.

◆ OR8() [4/5]

static constexpr uint8_t bits::OR8 ( uint8_t  val1,
uint8_t  val2,
uint8_t  val3,
uint8_t  val4,
uint8_t  val5 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands.

This method exists to ensure proper result cast to uint8_t.

Parameters
val1the first byte to be ORed.
val2the second byte to be ORed.
val3the third byte to be ORed.
val4the third byte to be ORed.
val5the third byte to be ORed.

Definition at line 320 of file bits.h.

◆ OR8() [5/5]

static constexpr uint8_t bits::OR8 ( uint8_t  val1,
uint8_t  val2,
uint8_t  val3,
uint8_t  val4,
uint8_t  val5,
uint8_t  val6 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands.

This method exists to ensure proper result cast to uint8_t.

Parameters
val1the first byte to be ORed.
val2the second byte to be ORed.
val3the third byte to be ORed.
val4the third byte to be ORed.
val5the third byte to be ORed.
val6the third byte to be ORed.

Definition at line 335 of file bits.h.

◆ IF8()

static constexpr uint8_t bits::IF8 ( bool  flag,
uint8_t  val 
)
staticconstexpr

return val if flag is true, otherwise 0, as an uint8_t.

Concretely, this is simply the (flag ? val : 0U) expression. This method exists to ensure proper result cast to uint8_t.

Parameters
flagthe flag used to determine if val should be returned or 0
valthe value returned if flag is true

Definition at line 347 of file bits.h.

◆ ORIF8() [1/5]

static constexpr uint8_t bits::ORIF8 ( bool  flag1,
uint8_t  val1,
bool  flag2,
uint8_t  val2 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags.

Concretely, this is simply the (flag1 ? val1 : 0) | (flag2 ? val2 : 0) expression.

Parameters
flag1the flag used to determine if val1 should be used or 0
val1the first byte to be ORed.
flag2the flag used to determine if val2 should be used or 0
val2the second byte to be ORed.

Definition at line 361 of file bits.h.

◆ ORIF8() [2/5]

static constexpr uint8_t bits::ORIF8 ( bool  flag1,
uint8_t  val1,
bool  flag2,
uint8_t  val2,
bool  flag3,
uint8_t  val3 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags.

Parameters
flag1the flag used to determine if val1 should be used or 0
val1the first byte to be ORed.
flag2the flag used to determine if val2 should be used or 0
val2the second byte to be ORed.
flag3the flag used to determine if val3 should be used or 0
val3the second byte to be ORed.

Definition at line 376 of file bits.h.

◆ ORIF8() [3/5]

static constexpr uint8_t bits::ORIF8 ( bool  flag1,
uint8_t  val1,
bool  flag2,
uint8_t  val2,
bool  flag3,
uint8_t  val3,
bool  flag4,
uint8_t  val4 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags.

Parameters
flag1the flag used to determine if val1 should be used or 0
val1the first byte to be ORed.
flag2the flag used to determine if val2 should be used or 0
val2the second byte to be ORed.
flag3the flag used to determine if val3 should be used or 0
val3the second byte to be ORed.
flag4the flag used to determine if val4 should be used or 0
val4the second byte to be ORed.

Definition at line 393 of file bits.h.

◆ ORIF8() [4/5]

static constexpr uint8_t bits::ORIF8 ( bool  flag1,
uint8_t  val1,
bool  flag2,
uint8_t  val2,
bool  flag3,
uint8_t  val3,
bool  flag4,
uint8_t  val4,
bool  flag5,
uint8_t  val5 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags.

Parameters
flag1the flag used to determine if val1 should be used or 0
val1the first byte to be ORed.
flag2the flag used to determine if val2 should be used or 0
val2the second byte to be ORed.
flag3the flag used to determine if val3 should be used or 0
val3the second byte to be ORed.
flag4the flag used to determine if val4 should be used or 0
val4the second byte to be ORed.
flag5the flag used to determine if val5 should be used or 0
val5the second byte to be ORed.

Definition at line 413 of file bits.h.

◆ ORIF8() [5/5]

static constexpr uint8_t bits::ORIF8 ( bool  flag1,
uint8_t  val1,
bool  flag2,
uint8_t  val2,
bool  flag3,
uint8_t  val3,
bool  flag4,
uint8_t  val4,
bool  flag5,
uint8_t  val5,
bool  flag6,
uint8_t  val6 
)
staticconstexpr

Create a uint8_t bitwise OR boolean operation between uint8_t operands, conditioned by bool flags.

Parameters
flag1the flag used to determine if val1 should be used or 0
val1the first byte to be ORed.
flag2the flag used to determine if val2 should be used or 0
val2the second byte to be ORed.
flag3the flag used to determine if val3 should be used or 0
val3the second byte to be ORed.
flag4the flag used to determine if val4 should be used or 0
val4the second byte to be ORed.
flag5the flag used to determine if val5 should be used or 0
val5the second byte to be ORed.
flag6the flag used to determine if val6 should be used or 0
val6the second byte to be ORed.

Definition at line 435 of file bits.h.