Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cBits Struct Reference

#include <cBits.h>

Inheritance diagram for Gray::cBits:
GrayLib::cBitArrayStatic GrayLib::cBitArray GrayLib::cBigUnsigned GrayLib::cBigInteger

Static Public Member Functions

static constexpr size_t GetSizeBytes (BIT_ENUM_t nBits) noexcept
 
template<typename TYPE >
static constexpr TYPE Mask1 (BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr bool IsMask1 (TYPE nVal) noexcept
 
template<typename TYPE >
static constexpr bool IsSet (TYPE nVal, BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr bool IsClear (TYPE nVal, BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr TYPE SetBit (TYPE nVal, BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr TYPE ClearBit (TYPE nVal, BIT_ENUM_t nBit) noexcept
 
template<typename TYPE >
static constexpr bool HasMask (TYPE nVal, TYPE nMask) noexcept
 
template<typename TYPE >
static BIT_ENUM_t Highest1Bit (TYPE nMask) noexcept
 
template<typename TYPE >
static BIT_ENUM_t Count1Bits (TYPE nMask) noexcept
 
template<typename TYPE >
static TYPE Rotl (TYPE nVal, BIT_ENUM_t nBits) noexcept
 
template<typename TYPE >
static TYPE Rotr (TYPE nVal, BIT_ENUM_t nBits) noexcept
 
template<typename TYPE >
static TYPE Reverse (TYPE nVal) noexcept
 
template<>
BIT_ENUM_t Count1Bits (UINT32 nVal) noexcept
 
template<>
BYTE Reverse (BYTE nVal) noexcept
 
template<>
UINT32 Reverse (UINT32 nVal) noexcept
 
template<>
ULONG Reverse (ULONG nVal) noexcept
 

Static Public Attributes

static const BYTE k_8 = 8
 represent the 8 bits in a byte. BIT_ENUM_t More...
 

Friends

class cBitsTests
 

Detailed Description

Bit mask type operations of all sorts. on various integral data types.

Member Function Documentation

◆ ClearBit()

template<typename TYPE >
static constexpr TYPE Gray::cBits::ClearBit ( TYPE  nVal,
BIT_ENUM_t  nBit 
)
inlinestaticconstexprnoexcept

◆ Count1Bits() [1/2]

template<typename TYPE >
static BIT_ENUM_t Gray::cBits::Count1Bits ( TYPE  nMask)
inlinestaticnoexcept

Count total number of 1 bits. like: __builtin_popcount()

◆ Count1Bits() [2/2]

template<>
BIT_ENUM_t Gray::cBits::Count1Bits ( UINT32  nVal)
inlinestaticnoexcept

A math trick for counting 1 bits in 32 bit numbers.

◆ GetSizeBytes()

static constexpr size_t Gray::cBits::GetSizeBytes ( BIT_ENUM_t  nBits)
inlinestaticconstexprnoexcept

How many bytes to hold these bits. Round up to next byte.

◆ HasMask()

template<typename TYPE >
static constexpr bool Gray::cBits::HasMask ( TYPE  nVal,
TYPE  nMask 
)
inlinestaticconstexprnoexcept

Any nMask bits set ?

◆ Highest1Bit()

template<typename TYPE >
static BIT_ENUM_t Gray::cBits::Highest1Bit ( TYPE  nMask)
inlinestaticnoexcept

What is the highest set bit in this primitive TYPE. 1 based. MSB.

Returns
1 for value of 1. 0 = no bits. e.g. nMask=8 return=4 similar to ffs() (POSIX) or builtin_clz(), __builtin_clzll (__GNUC) ? similar to _BitScanReverse, _BitScanReverse64. https://msdn.microsoft.com/en-us/library/fbxyd7zd.aspx x86 has BSR instruction. PowerPC there's a similar cntlz ("count leading zeros") instruction.

◆ IsClear()

template<typename TYPE >
static constexpr bool Gray::cBits::IsClear ( TYPE  nVal,
BIT_ENUM_t  nBit 
)
inlinestaticconstexprnoexcept

Test if a bit is NOT set.

◆ IsMask1()

template<typename TYPE >
static constexpr bool Gray::cBits::IsMask1 ( TYPE  nVal)
inlinestaticconstexprnoexcept

Does this just have a single bit on ? Is power of 2 ?

◆ IsSet()

template<typename TYPE >
static constexpr bool Gray::cBits::IsSet ( TYPE  nVal,
BIT_ENUM_t  nBit 
)
inlinestaticconstexprnoexcept

Test if a bit is set.

◆ Mask1()

template<typename TYPE >
static constexpr TYPE Gray::cBits::Mask1 ( BIT_ENUM_t  nBit)
inlinestaticconstexprnoexcept

Create a 1 bit mask of a given TYPE. Overflow/Underflow is just lost. _1BITMASK(nBit) = cBits::Mask1<size_t>(nBit). default TYPE = size_t

◆ Reverse() [1/4]

template<>
BYTE Gray::cBits::Reverse ( BYTE  nVal)
inlinestaticnoexcept

Reverse the order of the 8 bits. using 32 or 64 bit temporary. http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits

◆ Reverse() [2/4]

template<typename TYPE >
static TYPE Gray::cBits::Reverse ( TYPE  nVal)
inlinestaticnoexcept

Reverse the order of the bits. ASSUME not signed?

◆ Reverse() [3/4]

template<>
UINT32 Gray::cBits::Reverse ( UINT32  nVal)
inlinestaticnoexcept

Reverse the order of the 32 bits.

◆ Reverse() [4/4]

template<>
ULONG Gray::cBits::Reverse ( ULONG  nVal)
inlinestaticnoexcept

ULONG may be equiv to UINT32 or UINT64

◆ Rotl()

template<typename TYPE >
static TYPE Gray::cBits::Rotl ( TYPE  nVal,
BIT_ENUM_t  nBits 
)
inlinestaticnoexcept

Rotate bits left. If system doesn't have an inline rotate left function for X bits.

◆ Rotr()

template<typename TYPE >
static TYPE Gray::cBits::Rotr ( TYPE  nVal,
BIT_ENUM_t  nBits 
)
inlinestaticnoexcept

Rotate bits right.

◆ SetBit()

template<typename TYPE >
static constexpr TYPE Gray::cBits::SetBit ( TYPE  nVal,
BIT_ENUM_t  nBit 
)
inlinestaticconstexprnoexcept

Friends And Related Function Documentation

◆ cBitsTests

friend class cBitsTests
friend

Member Data Documentation

◆ k_8

const BYTE Gray::cBits::k_8 = 8
static

represent the 8 bits in a byte. BIT_ENUM_t


The documentation for this struct was generated from the following file: