GClasses
GClasses::GBits Class Reference

Detailed Description

Contains various functions for bit analysis.

#include <GBits.h>

Static Public Member Functions

static unsigned int binaryToGrayCode (unsigned int nBinary)
 Convert a number to its Gray code encoding. More...
 
static unsigned int boundingPowerOfTwo (unsigned int n)
 Returns the smallest power of 2 that is greater than or equal to n. More...
 
static size_t boundingShift (size_t n)
 Returns the fewest number of times that 1 must be shifted left to make a value greater than or equal to n. More...
 
static void bufferToHex (const unsigned char *pBuffer, size_t nBufferSize, char *pHexTwiceAsLarge)
 pHex should point to a buffer that is at 2 * nBufferSize + 1 More...
 
static void bufferToHexBigEndian (const unsigned char *pBuffer, size_t nBufferSize, char *pHexTwiceAsLarge)
 pHex should point to a buffer that is at 2 * nBufferSize + 1 More...
 
static void byteToHex (unsigned char byte, char *pHex)
 Converts a byte to two hex digits. The least significate digit will come first. the most significant digit comes next. More...
 
static void byteToHexBigEndian (unsigned char byte, char *pHex)
 Converts a byte to two hex digits. The least significate digit will come first. the most significant digit comes next. More...
 
static int compareDoubles (double a, double b)
 Returns -1 if a < b, 0 if a = b, and 1 if a > b. More...
 
static int compareInts (int a, int b)
 Returns -1 if a < b, 0 if a = b, and 1 if a > b. More...
 
static unsigned int countOnes (unsigned int n)
 Returns the number of 1's in the binary representation of n. More...
 
static size_t countTrailingZeros (size_t n)
 Returns the number of trailing zeros in the binary representation of n. For example, if n=712 (binary 1011001000), it will return 3. If n=0, it will return (size_t)-1 to represent inf. More...
 
static unsigned int grayCodeToBinary (unsigned int nGrayCode)
 Convert a number in Gray code encoding to a value. More...
 
static void hexToBuffer (const char *pHex, size_t nHexSize, unsigned char *pBuffer)
 pBuffer should be half the size of nHexSize More...
 
static void hexToBufferBigEndian (const char *pHex, size_t nHexSize, unsigned char *pBuffer)
 pBuffer should be half the size of nHexSize More...
 
static unsigned char hexToByte (char lsn, char msn)
 Converts two hexadecimal digits to a byte. lsn is least significant nybble. msn is most significant nybble. More...
 
static bool isPowerOfTwo (unsigned int n)
 Returns true if a number is a power of two. More...
 
static bool isValidFloat (const char *pString, size_t len)
 returns true iff the specified string is a valid floating point number. For example, it would return true for this string "-1.2e-14", but would return false for these: "e2", "2e", "-.", "2..3", "3-2", "2e3.5", "--1", etc. More...
 
static unsigned short littleEndianToN16 (unsigned short in)
 Convert little endian to a 16-bit native integer. More...
 
static short littleEndianToN16 (short in)
 Convert little endian to a 16-bit native integer. More...
 
static unsigned int littleEndianToN32 (unsigned int in)
 Convert little endian to a 32-bit native integer. More...
 
static int littleEndianToN32 (int in)
 Convert little endian to a 32-bit native integer. More...
 
static unsigned long long littleEndianToN64 (unsigned long long in)
 Convert little endian to a 64-bit native integer. More...
 
static long long littleEndianToN64 (long long in)
 Convert little endian to a 64-bit native integer. More...
 
static float littleEndianToR32 (float in)
 Convert little endian to a 32-bit native float. More...
 
static double littleEndianToR64 (double in)
 Convert little endian to a 64-bit native float. More...
 
static unsigned short n16ToLittleEndian (unsigned short in)
 Convert a 16-bit native integer to little endian. More...
 
static short n16ToLittleEndian (short in)
 Convert a 16-bit native integer to little endian. More...
 
static unsigned int n32ToLittleEndian (unsigned int in)
 Convert a 32-bit native integer to little endian. More...
 
static int n32ToLittleEndian (int in)
 Convert a 32-bit native integer to little endian. More...
 
static unsigned long long n64ToLittleEndian (unsigned long long in)
 Convert a 64-bit native integer to little endian. More...
 
static long long n64ToLittleEndian (long long in)
 Convert a 64-bit native integer to little endian. More...
 
static float r32ToLittleEndian (float in)
 Convert a 32-bit native float to little endian. More...
 
static double r64ToLittleEndian (double in)
 Convert a 64-bit native float to little endian. More...
 
static unsigned short reverseEndian (unsigned short in)
 Switch the endian of an unsigned integer. More...
 
static short reverseEndian (short in)
 Switch the endian of an unsigned integer. More...
 
static unsigned int reverseEndian (unsigned int in)
 Switch the endian of an unsigned integer. More...
 
static int reverseEndian (int in)
 Switch the endian of an integer. More...
 
static unsigned long long reverseEndian (unsigned long long in)
 Switch the endian of a double. More...
 
static long long reverseEndian (long long in)
 Switch the endian of a double. More...
 
static float reverseEndian (float in)
 Switch the endian of a float. More...
 
static double reverseEndian (double in)
 Switch the endian of a double. More...
 
static int sign (int n)
 Returns the sign (-1, 0, +1) of an integer. More...
 
static int sign (double d)
 Returns the sign of d. More...
 
static void test ()
 

Member Function Documentation

static unsigned int GClasses::GBits::binaryToGrayCode ( unsigned int  nBinary)
inlinestatic

Convert a number to its Gray code encoding.

static unsigned int GClasses::GBits::boundingPowerOfTwo ( unsigned int  n)
inlinestatic

Returns the smallest power of 2 that is greater than or equal to n.

static size_t GClasses::GBits::boundingShift ( size_t  n)
inlinestatic

Returns the fewest number of times that 1 must be shifted left to make a value greater than or equal to n.

static void GClasses::GBits::bufferToHex ( const unsigned char *  pBuffer,
size_t  nBufferSize,
char *  pHexTwiceAsLarge 
)
inlinestatic

pHex should point to a buffer that is at 2 * nBufferSize + 1

static void GClasses::GBits::bufferToHexBigEndian ( const unsigned char *  pBuffer,
size_t  nBufferSize,
char *  pHexTwiceAsLarge 
)
inlinestatic

pHex should point to a buffer that is at 2 * nBufferSize + 1

static void GClasses::GBits::byteToHex ( unsigned char  byte,
char *  pHex 
)
inlinestatic

Converts a byte to two hex digits. The least significate digit will come first. the most significant digit comes next.

static void GClasses::GBits::byteToHexBigEndian ( unsigned char  byte,
char *  pHex 
)
inlinestatic

Converts a byte to two hex digits. The least significate digit will come first. the most significant digit comes next.

static int GClasses::GBits::compareDoubles ( double  a,
double  b 
)
inlinestatic

Returns -1 if a < b, 0 if a = b, and 1 if a > b.

static int GClasses::GBits::compareInts ( int  a,
int  b 
)
inlinestatic

Returns -1 if a < b, 0 if a = b, and 1 if a > b.

static unsigned int GClasses::GBits::countOnes ( unsigned int  n)
inlinestatic

Returns the number of 1's in the binary representation of n.

static size_t GClasses::GBits::countTrailingZeros ( size_t  n)
inlinestatic

Returns the number of trailing zeros in the binary representation of n. For example, if n=712 (binary 1011001000), it will return 3. If n=0, it will return (size_t)-1 to represent inf.

static unsigned int GClasses::GBits::grayCodeToBinary ( unsigned int  nGrayCode)
inlinestatic

Convert a number in Gray code encoding to a value.

static void GClasses::GBits::hexToBuffer ( const char *  pHex,
size_t  nHexSize,
unsigned char *  pBuffer 
)
inlinestatic

pBuffer should be half the size of nHexSize

static void GClasses::GBits::hexToBufferBigEndian ( const char *  pHex,
size_t  nHexSize,
unsigned char *  pBuffer 
)
inlinestatic

pBuffer should be half the size of nHexSize

static unsigned char GClasses::GBits::hexToByte ( char  lsn,
char  msn 
)
inlinestatic

Converts two hexadecimal digits to a byte. lsn is least significant nybble. msn is most significant nybble.

static bool GClasses::GBits::isPowerOfTwo ( unsigned int  n)
inlinestatic

Returns true if a number is a power of two.

static bool GClasses::GBits::isValidFloat ( const char *  pString,
size_t  len 
)
static

returns true iff the specified string is a valid floating point number. For example, it would return true for this string "-1.2e-14", but would return false for these: "e2", "2e", "-.", "2..3", "3-2", "2e3.5", "--1", etc.

static unsigned short GClasses::GBits::littleEndianToN16 ( unsigned short  in)
inlinestatic

Convert little endian to a 16-bit native integer.

static short GClasses::GBits::littleEndianToN16 ( short  in)
inlinestatic

Convert little endian to a 16-bit native integer.

static unsigned int GClasses::GBits::littleEndianToN32 ( unsigned int  in)
inlinestatic

Convert little endian to a 32-bit native integer.

static int GClasses::GBits::littleEndianToN32 ( int  in)
inlinestatic

Convert little endian to a 32-bit native integer.

static unsigned long long GClasses::GBits::littleEndianToN64 ( unsigned long long  in)
inlinestatic

Convert little endian to a 64-bit native integer.

static long long GClasses::GBits::littleEndianToN64 ( long long  in)
inlinestatic

Convert little endian to a 64-bit native integer.

static float GClasses::GBits::littleEndianToR32 ( float  in)
inlinestatic

Convert little endian to a 32-bit native float.

static double GClasses::GBits::littleEndianToR64 ( double  in)
inlinestatic

Convert little endian to a 64-bit native float.

static unsigned short GClasses::GBits::n16ToLittleEndian ( unsigned short  in)
inlinestatic

Convert a 16-bit native integer to little endian.

static short GClasses::GBits::n16ToLittleEndian ( short  in)
inlinestatic

Convert a 16-bit native integer to little endian.

static unsigned int GClasses::GBits::n32ToLittleEndian ( unsigned int  in)
inlinestatic

Convert a 32-bit native integer to little endian.

static int GClasses::GBits::n32ToLittleEndian ( int  in)
inlinestatic

Convert a 32-bit native integer to little endian.

static unsigned long long GClasses::GBits::n64ToLittleEndian ( unsigned long long  in)
inlinestatic

Convert a 64-bit native integer to little endian.

static long long GClasses::GBits::n64ToLittleEndian ( long long  in)
inlinestatic

Convert a 64-bit native integer to little endian.

static float GClasses::GBits::r32ToLittleEndian ( float  in)
inlinestatic

Convert a 32-bit native float to little endian.

static double GClasses::GBits::r64ToLittleEndian ( double  in)
inlinestatic

Convert a 64-bit native float to little endian.

static unsigned short GClasses::GBits::reverseEndian ( unsigned short  in)
inlinestatic

Switch the endian of an unsigned integer.

static short GClasses::GBits::reverseEndian ( short  in)
inlinestatic

Switch the endian of an unsigned integer.

static unsigned int GClasses::GBits::reverseEndian ( unsigned int  in)
inlinestatic

Switch the endian of an unsigned integer.

static int GClasses::GBits::reverseEndian ( int  in)
inlinestatic

Switch the endian of an integer.

static unsigned long long GClasses::GBits::reverseEndian ( unsigned long long  in)
inlinestatic

Switch the endian of a double.

static long long GClasses::GBits::reverseEndian ( long long  in)
inlinestatic

Switch the endian of a double.

static float GClasses::GBits::reverseEndian ( float  in)
inlinestatic

Switch the endian of a float.

static double GClasses::GBits::reverseEndian ( double  in)
inlinestatic

Switch the endian of a double.

static int GClasses::GBits::sign ( int  n)
inlinestatic

Returns the sign (-1, 0, +1) of an integer.

static int GClasses::GBits::sign ( double  d)
inlinestatic

Returns the sign of d.

static void GClasses::GBits::test ( )
static