Quick Links:

bal | bbl | bdl | bsl

Public Types | Static Public Member Functions

bdlb::BitUtil Struct Reference

#include <bdlb_bitutil.h>

List of all members.

Public Types

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

Static Public Member Functions

static bool isBitSet (uint32_t value, int index)
static bool isBitSet (uint64_t value, int index)
static int log2 (uint32_t value)
static int log2 (uint64_t value)
static int numBitsSet (uint32_t value)
static int numBitsSet (uint64_t value)
static int numLeadingUnsetBits (uint32_t value)
static int numLeadingUnsetBits (uint64_t value)
static int numTrailingUnsetBits (uint32_t value)
static int numTrailingUnsetBits (uint64_t value)
static uint32_t roundUp (uint32_t value, uint32_t boundary)
static uint64_t roundUp (uint64_t value, uint64_t boundary)
static uint32_t roundUpToBinaryPower (uint32_t value)
static uint64_t roundUpToBinaryPower (uint64_t value)
template<class INTEGER >
static int sizeInBits (INTEGER value)
static uint32_t withBitCleared (uint32_t value, int index)
static uint64_t withBitCleared (uint64_t value, int index)
static uint32_t withBitSet (uint32_t value, int index)
static uint64_t withBitSet (uint64_t 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 integer types uint32_t and uint64_t, respectively.

See Component bdlb_bitutil


Member Typedef Documentation

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

Member Function Documentation

static bool bdlb::BitUtil::isBitSet ( uint32_t  value,
int  index 
) [static]
static bool bdlb::BitUtil::isBitSet ( uint64_t  value,
int  index 
) [static]

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).

static int bdlb::BitUtil::log2 ( uint32_t  value  )  [static]
static int bdlb::BitUtil::log2 ( uint64_t  value  )  [static]

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

static int bdlb::BitUtil::numBitsSet ( uint32_t  value  )  [static]
static int bdlb::BitUtil::numBitsSet ( uint64_t  value  )  [static]

Return the number of 1 bits in the specified value.

static int bdlb::BitUtil::numLeadingUnsetBits ( uint32_t  value  )  [static]
static int bdlb::BitUtil::numLeadingUnsetBits ( uint64_t  value  )  [static]

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

static int bdlb::BitUtil::numTrailingUnsetBits ( uint32_t  value  )  [static]
static int bdlb::BitUtil::numTrailingUnsetBits ( uint64_t  value  )  [static]

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

static uint32_t bdlb::BitUtil::roundUp ( uint32_t  value,
uint32_t  boundary 
) [static]
static uint64_t bdlb::BitUtil::roundUp ( uint64_t  value,
uint64_t  boundary 
) [static]

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.

static uint32_t bdlb::BitUtil::roundUpToBinaryPower ( uint32_t  value  )  [static]
static uint64_t bdlb::BitUtil::roundUpToBinaryPower ( uint64_t  value  )  [static]

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))

template<class INTEGER >
static int bdlb::BitUtil::sizeInBits ( INTEGER  value  )  [static]

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

static uint32_t bdlb::BitUtil::withBitCleared ( uint32_t  value,
int  index 
) [static]
static uint64_t bdlb::BitUtil::withBitCleared ( uint64_t  value,
int  index 
) [static]

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).

static uint32_t bdlb::BitUtil::withBitSet ( uint32_t  value,
int  index 
) [static]
static uint64_t bdlb::BitUtil::withBitSet ( uint64_t  value,
int  index 
) [static]

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).


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