libcommonc++  0.7
Numeric Class Reference

Numeric and bitwise utility functions. More...

#include <Numeric.h++>

Static Public Member Functions

static uint32_t nextPowerOf2 (uint32_t value)
 Calculate the next higher power of 2 for a value. More...
 
static uint32_t leastSignificantSetBit (uint32_t value)
 Find the least significant bit that is set in a value. More...
 
static uint64_t leastSignificantSetBit (uint64_t value)
 Find the least significant bit that is set in a value. More...
 
static uint32_t mostSignificantSetBit (uint32_t value)
 Find the most significant bit that is set in a value. More...
 
static uint64_t mostSignificantSetBit (uint64_t value)
 Find the most significant bit that is set in a value. More...
 
static uint_t countSetBits (uint32_t value)
 Count the number of bits that are set in a value. More...
 
static uint_t countSetBits (uint64_t value)
 Count the number of bits that are set in a value. More...
 
static uint_t countLeadingZeroes (uint32_t value)
 Count the number of leading zeroes in a value. More...
 
static uint_t countLeadingZeroes (uint64_t value)
 Count the number of leading zeroes in a value. More...
 
static uint_t countTrailingZeroes (uint32_t value)
 Count the number of trailing zeroes in a value. More...
 
static uint_t countTrailingZeroes (uint64_t value)
 Count the number of trailing zeroes in a value. More...
 

Detailed Description

Numeric and bitwise utility functions.

Algorithms taken from http://aggregate.org/MAGIC

Author
Mark Lindner

Member Function Documentation

◆ countLeadingZeroes() [1/2]

uint_t countLeadingZeroes ( uint32_t  value)
static

Count the number of leading zeroes in a value.

Parameters
valueThe value.
Returns
The number of leading zeroes in the value.

◆ countLeadingZeroes() [2/2]

uint_t countLeadingZeroes ( uint64_t  value)
static

Count the number of leading zeroes in a value.

Parameters
valueThe value.
Returns
The number of leading zeroes in the value.

◆ countSetBits() [1/2]

uint_t countSetBits ( uint32_t  value)
static

Count the number of bits that are set in a value.

Parameters
valueThe value.
Returns
The count of bits that are set in the value.

◆ countSetBits() [2/2]

uint_t countSetBits ( uint64_t  value)
static

Count the number of bits that are set in a value.

Parameters
valueThe value.
Returns
The count of bits that are set in the value.

◆ countTrailingZeroes() [1/2]

uint_t countTrailingZeroes ( uint32_t  value)
static

Count the number of trailing zeroes in a value.

Parameters
valueThe value.
Returns
The number of trailing zeroes in the value.

◆ countTrailingZeroes() [2/2]

uint_t countTrailingZeroes ( uint64_t  value)
static

Count the number of trailing zeroes in a value.

Parameters
valueThe value.
Returns
The number of trailing zeroes in the value.

◆ leastSignificantSetBit() [1/2]

uint32_t leastSignificantSetBit ( uint32_t  value)
static

Find the least significant bit that is set in a value.

Parameters
valueThe value.
Returns
A value with the same least significant bit set as the input, but with all other bits clear.

◆ leastSignificantSetBit() [2/2]

uint64_t leastSignificantSetBit ( uint64_t  value)
static

Find the least significant bit that is set in a value.

Parameters
valueThe value.
Returns
A value with the same least significant bit set as the input, but with all other bits clear.

◆ mostSignificantSetBit() [1/2]

uint32_t mostSignificantSetBit ( uint32_t  value)
static

Find the most significant bit that is set in a value.

Parameters
valueThe value.
Returns
A value with the same most significant bit set as the input, but with all other bits clear.

◆ mostSignificantSetBit() [2/2]

uint64_t mostSignificantSetBit ( uint64_t  value)
static

Find the most significant bit that is set in a value.

Parameters
valueThe value.
Returns
A value with the same most significant bit set as the input, but with all other bits clear.

◆ nextPowerOf2()

uint32_t nextPowerOf2 ( uint32_t  value)
static

Calculate the next higher power of 2 for a value.

Parameters
valueThe value.
Returns
The smallest power of 2 that is greater than or equal to the value, or 0 if the value is 0 or greater than 2^31.

The documentation for this class was generated from the following files: