BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlb::BitUtil Struct Reference

#include <bdlb_bitutil.h>

Public Types

typedef bsl::uint32_t uint32_t
 
typedef bsl::uint64_t uint64_t
 

Public Member Functions

template<class TYPE >
int sizeInBits (TYPE)
 

Static Public Member Functions

static bool isBitSet (unsigned int value, int index)
 
static bool isBitSet (unsigned long value, int index)
 
static bool isBitSet (unsigned long long value, int index)
 
static int log2 (unsigned int value)
 
static int log2 (unsigned long value)
 
static int log2 (unsigned long long value)
 
static int numBitsSet (unsigned int value)
 
static int numBitsSet (unsigned long value)
 
static int numBitsSet (unsigned long long value)
 Return the number of 1 bits in the specified value.
 
static int numLeadingUnsetBits (unsigned int value)
 
static int numLeadingUnsetBits (unsigned long value)
 
static int numLeadingUnsetBits (unsigned long long value)
 
static int numTrailingUnsetBits (unsigned int value)
 
static int numTrailingUnsetBits (unsigned long value)
 
static int numTrailingUnsetBits (unsigned long long value)
 
static unsigned int roundUp (unsigned int value, unsigned int boundary)
 
static unsigned long roundUp (unsigned long value, unsigned long boundary)
 
static unsigned long long roundUp (unsigned long long value, unsigned long long boundary)
 
static unsigned int roundUpToBinaryPower (unsigned int value)
 
static unsigned long roundUpToBinaryPower (unsigned long value)
 
static unsigned long long roundUpToBinaryPower (unsigned long long value)
 
template<class INTEGER >
static int sizeInBits (INTEGER value=0)
 
static unsigned int withBitCleared (unsigned int value, int index)
 
static unsigned long withBitCleared (unsigned long value, int index)
 
static unsigned long long withBitCleared (unsigned long long value, int index)
 
static unsigned int withBitSet (unsigned int value, int index)
 
static unsigned long withBitSet (unsigned long value, int index)
 
static unsigned long long withBitSet (unsigned long long value, int index)
 

Detailed Description

This utility struct provides a namespace for a set of bit-level, stateless functions that operate on the built-in 32- and 64-bit unsigned integer types.

Member Typedef Documentation

◆ uint32_t

typedef bsl::uint32_t bdlb::BitUtil::uint32_t

◆ uint64_t

typedef bsl::uint64_t bdlb::BitUtil::uint64_t

Member Function Documentation

◆ isBitSet() [1/3]

bool bdlb::BitUtil::isBitSet ( unsigned int  value,
int  index 
)
inlinestatic

◆ isBitSet() [2/3]

bool bdlb::BitUtil::isBitSet ( unsigned long long  value,
int  index 
)
inlinestatic

Return true if the bit in the specified value at the specified index is set to 1, and false otherwise. The behavior is undefined unless 0 <= index < sizeInBits(value).

◆ isBitSet() [3/3]

bool bdlb::BitUtil::isBitSet ( unsigned long  value,
int  index 
)
inlinestatic

◆ log2() [1/3]

int bdlb::BitUtil::log2 ( unsigned int  value)
inlinestatic

◆ log2() [2/3]

int bdlb::BitUtil::log2 ( unsigned long long  value)
inlinestatic

Return the base-2 logarithm of the specified value rounded up to the nearest integer. The behavior is undefined unless 0 < value.

◆ log2() [3/3]

int bdlb::BitUtil::log2 ( unsigned long  value)
inlinestatic

◆ numBitsSet() [1/3]

int bdlb::BitUtil::numBitsSet ( unsigned int  value)
inlinestatic

◆ numBitsSet() [2/3]

int bdlb::BitUtil::numBitsSet ( unsigned long long  value)
inlinestatic

◆ numBitsSet() [3/3]

int bdlb::BitUtil::numBitsSet ( unsigned long  value)
inlinestatic

◆ numLeadingUnsetBits() [1/3]

int bdlb::BitUtil::numLeadingUnsetBits ( unsigned int  value)
inlinestatic

◆ numLeadingUnsetBits() [2/3]

int bdlb::BitUtil::numLeadingUnsetBits ( unsigned long long  value)
inlinestatic

Return the number of consecutive 0 bits starting from the most-significant bit in the specified value.

◆ numLeadingUnsetBits() [3/3]

int bdlb::BitUtil::numLeadingUnsetBits ( unsigned long  value)
inlinestatic

◆ numTrailingUnsetBits() [1/3]

int bdlb::BitUtil::numTrailingUnsetBits ( unsigned int  value)
inlinestatic

◆ numTrailingUnsetBits() [2/3]

int bdlb::BitUtil::numTrailingUnsetBits ( unsigned long long  value)
inlinestatic

Return the number of consecutive 0 bits starting from the least-significant bit in the specified value.

◆ numTrailingUnsetBits() [3/3]

int bdlb::BitUtil::numTrailingUnsetBits ( unsigned long  value)
inlinestatic

◆ roundUp() [1/3]

unsigned int bdlb::BitUtil::roundUp ( unsigned int  value,
unsigned int  boundary 
)
inlinestatic

◆ roundUp() [2/3]

unsigned long long bdlb::BitUtil::roundUp ( unsigned long long  value,
unsigned long long  boundary 
)
inlinestatic

Return the least multiple of the specified boundary that is greater than or equal to the specified value, and 0 if 0 == value or the conversion was not successful. The behavior is undefined unless 1 == numBitsSet(boundary). Note that the conversion will succeed if and only if 0 == value % boundary or (1 << sizeInBits(value)) > (value / boundary + 1) * boundary.

◆ roundUp() [3/3]

unsigned long bdlb::BitUtil::roundUp ( unsigned long  value,
unsigned long  boundary 
)
inlinestatic

◆ roundUpToBinaryPower() [1/3]

unsigned int bdlb::BitUtil::roundUpToBinaryPower ( unsigned int  value)
inlinestatic

◆ roundUpToBinaryPower() [2/3]

unsigned long long bdlb::BitUtil::roundUpToBinaryPower ( unsigned long long  value)
inlinestatic

Return the least power of 2 that is greater than or equal to the specified value, and 0 if the conversion was not successful. Note that the conversion will succeed if and only if 0 < value <= (1 << (sizeInBits(value) - 1))

◆ roundUpToBinaryPower() [3/3]

unsigned long bdlb::BitUtil::roundUpToBinaryPower ( unsigned long  value)
inlinestatic

◆ sizeInBits() [1/2]

template<class INTEGER >
static int bdlb::BitUtil::sizeInBits ( INTEGER  value = 0)
static

Return the number of bits in the specified value of the (template parameter) type INTEGER.

◆ sizeInBits() [2/2]

template<class TYPE >
int bdlb::BitUtil::sizeInBits ( TYPE  )
inline

◆ withBitCleared() [1/3]

unsigned int bdlb::BitUtil::withBitCleared ( unsigned int  value,
int  index 
)
inlinestatic

◆ withBitCleared() [2/3]

unsigned long long bdlb::BitUtil::withBitCleared ( unsigned long long  value,
int  index 
)
inlinestatic

Return the result of replacing the bit at the specified index in the specified value with 0, transferring all other bits from value unchanged. The behavior is undefined unless 0 <= index < sizeInBits(value).

◆ withBitCleared() [3/3]

unsigned long bdlb::BitUtil::withBitCleared ( unsigned long  value,
int  index 
)
inlinestatic

◆ withBitSet() [1/3]

unsigned int bdlb::BitUtil::withBitSet ( unsigned int  value,
int  index 
)
inlinestatic

◆ withBitSet() [2/3]

unsigned long long bdlb::BitUtil::withBitSet ( unsigned long long  value,
int  index 
)
inlinestatic

Return the result of replacing the bit at the specified index in the specified value with 1, transferring all other bits from value unchanged. The behavior is undefined unless 0 <= index < sizeInBits(value).

◆ withBitSet() [3/3]

unsigned long bdlb::BitUtil::withBitSet ( unsigned long  value,
int  index 
)
inlinestatic

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