The bits of an unsigned integer, read and written by static functions, as a register, a byte of a frame or a word of a hash.
More...
#include <Bit.h>
|
|
| Bit ()=delete |
| | Deleted: the functions are static, no Bit is made.
|
|
| static constexpr Integer | ToMask (uint8_t position) |
| | Returns the mask of the bit at position.
|
| static constexpr Integer | Combine (Integer first, Integer second) |
| | Returns the bits set in either of two values: the mask of a group from the masks of its parts, or a value put together from its parts.
|
| static constexpr bool | ReadBit (Integer value, uint8_t position) |
| | Returns whether the bit at position of value is set.
|
| static constexpr Integer | WriteBit (Integer value, uint8_t position, bool set) |
| | Returns value with the bit at position set or cleared.
|
| static constexpr Integer | ReadBitGroup (Integer value, Integer mask) |
| | Returns the bits of value that mask selects, where they stand.
|
| static constexpr Integer | ReadBitGroup (Integer value, Integer mask, uint8_t position) |
| | Returns the group of bits of value that starts at position, shifted down to bit 0.
|
| static constexpr Integer | ToggleBits (Integer value, Integer mask) |
| | Returns value with the bits of mask inverted, the others as they were.
|
| static constexpr Integer | Invert (Integer value) |
| | Returns value with every bit inverted.
|
| static constexpr Integer | ShiftUp (Integer value, uint8_t places) |
| | Returns value moved places up; the bits beyond the top fall out.
|
| static constexpr Integer | ShiftDown (Integer value, uint8_t places) |
| | Returns value moved places down; the bits below bit 0 fall out.
|
| static constexpr Integer | RotateLeft (Integer value, uint8_t places) |
| | Returns value moved places up, the bits beyond the top coming in again at the bottom.
|
| template<typename Target> |
| static void | SetBits (Target &target, Integer mask) |
| | Sets the bits of mask in target, the other bits left as they were.
|
| template<typename Target> |
| static void | ClearBits (Target &target, Integer mask) |
| | Clears the bits of mask in target, the other bits left as they were.
|
template<typename Integer>
class max_matrix::Bit< Integer >
The bits of an unsigned integer, read and written by static functions, as a register, a byte of a frame or a word of a hash.
static constexpr bool ReadBit(Integer value, uint8_t position)
Returns whether the bit at position of value is set.
Definition Bit.h:87
static void SetBits(Target &target, Integer mask)
Sets the bits of mask in target, the other bits left as they were.
Definition Bit.h:201
A position counts from 0, the least significant bit. A group of bits is given by its mask as it stands in the value; ReadBitGroup() with a position is for a mask written down unshifted, as a datasheet gives a field.
A value is shifted as an unsigned int where Integer is narrower: a uint8_t would be promoted to an int, which has a sign and, on the AVR, 16 bits.
- Template Parameters
-
| Integer | The unsigned integer, as uint8_t or uint32_t; not bool. |
- Precondition
- Each position and number of places lies below the width of Integer; a shift by as much is undefined.
◆ ClearBits()
template<typename Integer>
template<typename Target>
| void max_matrix::Bit< Integer >::ClearBits |
( |
Target & | target, |
|
|
Integer | mask ) |
|
inlinestatic |
Clears the bits of mask in target, the other bits left as they were.
- Template Parameters
-
| Target | The type of the target, as for SetBits(). |
- Parameters
-
| [in,out] | target | The register or variable to change. |
| [in] | mask | The bits to clear. |
- Warning
- It reads the target, changes it and writes it back, and not atomically; see SetBits().
◆ Combine()
template<typename Integer>
| constexpr Integer max_matrix::Bit< Integer >::Combine |
( |
Integer | first, |
|
|
Integer | second ) |
|
inlinestaticconstexpr |
Returns the bits set in either of two values: the mask of a group from the masks of its parts, or a value put together from its parts.
What a | of named masks does in a constexpr, the one place it may stand outside this class (docs/CodingStyle.md H-9); this anywhere.
- Parameters
-
| [in] | first | The one value. |
| [in] | second | The other. |
- Returns
- Every bit that is set in one of them.
◆ Invert()
template<typename Integer>
Returns value with every bit inverted.
- Parameters
-
- Returns
- The bits that are not set in value.
◆ ReadBit()
template<typename Integer>
| constexpr bool max_matrix::Bit< Integer >::ReadBit |
( |
Integer | value, |
|
|
uint8_t | position ) |
|
inlinestaticconstexpr |
Returns whether the bit at position of value is set.
- Parameters
-
| [in] | value | The integer to read. |
| [in] | position | The position of the bit. |
◆ ReadBitGroup() [1/2]
template<typename Integer>
| constexpr Integer max_matrix::Bit< Integer >::ReadBitGroup |
( |
Integer | value, |
|
|
Integer | mask ) |
|
inlinestaticconstexpr |
Returns the bits of value that mask selects, where they stand.
- Parameters
-
| [in] | value | The integer to read. |
| [in] | mask | The group as it stands in the value. |
- Returns
- The bits of the group in place, every other bit cleared.
◆ ReadBitGroup() [2/2]
template<typename Integer>
| constexpr Integer max_matrix::Bit< Integer >::ReadBitGroup |
( |
Integer | value, |
|
|
Integer | mask, |
|
|
uint8_t | position ) |
|
inlinestaticconstexpr |
Returns the group of bits of value that starts at position, shifted down to bit 0.
- Parameters
-
| [in] | value | The integer to read. |
| [in] | mask | The group written down unshifted, from bit 0 on. |
| [in] | position | The position of the group's lowest bit in value. |
- Returns
- The bits of the group from bit 0 on, every other bit cleared.
◆ RotateLeft()
template<typename Integer>
| constexpr Integer max_matrix::Bit< Integer >::RotateLeft |
( |
Integer | value, |
|
|
uint8_t | places ) |
|
inlinestaticconstexpr |
Returns value moved places up, the bits beyond the top coming in again at the bottom.
- Parameters
-
| [in] | value | The integer. |
| [in] | places | The number of places, 1 to the width less 1. |
◆ SetBits()
template<typename Integer>
template<typename Target>
Sets the bits of mask in target, the other bits left as they were.
- Template Parameters
-
| Target | The type of the target: uint8_t volatile for a port, an Integer for a variable, or what stands for a port with |= and &= of its own, as the mock of the tests does, so that every bit reaches its pin there. |
- Parameters
-
| [in,out] | target | The register or variable to change. |
| [in] | mask | The bits to set. |
- Warning
- It reads the target, changes it and writes it back, as |= on a register does, and not atomically: a target that an interrupt writes as well needs the caller's guard. Not for a register of flags, where writing back a 1 that was read clears a flag, nor for PINB and its like, where a 1 written toggles the pin.
◆ ShiftDown()
template<typename Integer>
| constexpr Integer max_matrix::Bit< Integer >::ShiftDown |
( |
Integer | value, |
|
|
uint8_t | places ) |
|
inlinestaticconstexpr |
Returns value moved places down; the bits below bit 0 fall out.
- Parameters
-
| [in] | value | The integer. |
| [in] | places | The number of places. |
◆ ShiftUp()
template<typename Integer>
| constexpr Integer max_matrix::Bit< Integer >::ShiftUp |
( |
Integer | value, |
|
|
uint8_t | places ) |
|
inlinestaticconstexpr |
Returns value moved places up; the bits beyond the top fall out.
- Parameters
-
| [in] | value | The integer. |
| [in] | places | The number of places. |
◆ ToggleBits()
template<typename Integer>
| constexpr Integer max_matrix::Bit< Integer >::ToggleBits |
( |
Integer | value, |
|
|
Integer | mask ) |
|
inlinestaticconstexpr |
Returns value with the bits of mask inverted, the others as they were.
- Parameters
-
| [in] | value | The integer to change. |
| [in] | mask | The bits to invert. |
- Returns
- The changed integer.
◆ ToMask()
template<typename Integer>
Returns the mask of the bit at position.
- Parameters
-
| [in] | position | The position of the bit. |
- Returns
- An integer with that bit set and every other bit cleared.
◆ WriteBit()
template<typename Integer>
| constexpr Integer max_matrix::Bit< Integer >::WriteBit |
( |
Integer | value, |
|
|
uint8_t | position, |
|
|
bool | set ) |
|
inlinestaticconstexpr |
Returns value with the bit at position set or cleared.
- Parameters
-
| [in] | value | The integer to change. |
| [in] | position | The position of the bit. |
| [in] | set | True to set the bit, false to clear it. |
- Returns
- The changed integer.
The documentation for this class was generated from the following file: