GClasses

GClasses::GBits Class Reference

Contains various functions for bit analysis. More...

#include <GBits.h>

List of all members.

Static Public Member Functions

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.
static int compareInts (int a, int b)
 Returns -1 if a < b, 0 if a = b, and 1 if a > b.
static int compareDoubles (double a, double b)
 Returns -1 if a < b, 0 if a = b, and 1 if a > b.
static unsigned int binaryToGrayCode (unsigned int nBinary)
 Convert a number to its Gray code encoding.
static unsigned int grayCodeToBinary (unsigned int nGrayCode)
 Convert a number in Gray code encoding to a value.
static unsigned int countOnes (unsigned int n)
 Returns the number of 1's in the binary representation of n.
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.
static bool isPowerOfTwo (unsigned int n)
 Returns true if a number is a power of two.
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.
static unsigned int boundingPowerOfTwo (unsigned int n)
 Returns the smallest power of 2 that is greater than or equal to n.
static int sign (int n)
 Returns the sign (-1, 0, +1) of an integer.
static int sign (double d)
 Returns the sign of d.
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.
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.
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.
static void bufferToHex (const unsigned char *pBuffer, size_t nBufferSize, char *pHexTwiceAsLarge)
 pHex should point to a buffer that is at 2 * nBufferSize + 1
static void bufferToHexBigEndian (const unsigned char *pBuffer, size_t nBufferSize, char *pHexTwiceAsLarge)
 pHex should point to a buffer that is at 2 * nBufferSize + 1
static void hexToBuffer (const char *pHex, size_t nHexSize, unsigned char *pBuffer)
 pBuffer should be half the size of nHexSize
static void hexToBufferBigEndian (const char *pHex, size_t nHexSize, unsigned char *pBuffer)
 pBuffer should be half the size of nHexSize
static unsigned long long n64ToLittleEndian (unsigned long long in)
 Convert a 64-bit native integer to little endian.
static long long n64ToLittleEndian (long long in)
 Convert a 64-bit native integer to little endian.
static unsigned int n32ToLittleEndian (unsigned int in)
 Convert a 32-bit native integer to little endian.
static int n32ToLittleEndian (int in)
 Convert a 32-bit native integer to little endian.
static unsigned short n16ToLittleEndian (unsigned short in)
 Convert a 16-bit native integer to little endian.
static short n16ToLittleEndian (short in)
 Convert a 16-bit native integer to little endian.
static float r32ToLittleEndian (float in)
 Convert a 32-bit native float to little endian.
static double r64ToLittleEndian (double in)
 Convert a 64-bit native float to little endian.
static unsigned long long littleEndianToN64 (unsigned long long in)
 Convert little endian to a 64-bit native integer.
static long long littleEndianToN64 (long long in)
 Convert little endian to a 64-bit native integer.
static unsigned int littleEndianToN32 (unsigned int in)
 Convert little endian to a 32-bit native integer.
static int littleEndianToN32 (int in)
 Convert little endian to a 32-bit native integer.
static unsigned short littleEndianToN16 (unsigned short in)
 Convert little endian to a 16-bit native integer.
static short littleEndianToN16 (short in)
 Convert little endian to a 16-bit native integer.
static float littleEndianToR32 (float in)
 Convert little endian to a 32-bit native float.
static double littleEndianToR64 (double in)
 Convert little endian to a 64-bit native float.
static unsigned short reverseEndian (unsigned short in)
 Switch the endian of an unsigned integer.
static short reverseEndian (short in)
 Switch the endian of an unsigned integer.
static unsigned int reverseEndian (unsigned int in)
 Switch the endian of an unsigned integer.
static int reverseEndian (int in)
 Switch the endian of an integer.
static unsigned long long reverseEndian (unsigned long long in)
 Switch the endian of a double.
static long long reverseEndian (long long in)
 Switch the endian of a double.
static float reverseEndian (float in)
 Switch the endian of a float.
static double reverseEndian (double in)
 Switch the endian of a double.
static void test ()

Detailed Description

Contains various functions for bit analysis.


Member Function Documentation

static unsigned int GClasses::GBits::binaryToGrayCode ( unsigned int  nBinary) [inline, static]

Convert a number to its Gray code encoding.

static unsigned int GClasses::GBits::boundingPowerOfTwo ( unsigned int  n) [inline, static]

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

static size_t GClasses::GBits::boundingShift ( size_t  n) [inline, static]

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 
) [inline, static]

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 
) [inline, static]

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

static void GClasses::GBits::byteToHex ( unsigned char  byte,
char *  pHex 
) [inline, static]

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 
) [inline, static]

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 
) [inline, static]

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

static int GClasses::GBits::compareInts ( int  a,
int  b 
) [inline, static]

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

static unsigned int GClasses::GBits::countOnes ( unsigned int  n) [inline, static]

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

static size_t GClasses::GBits::countTrailingZeros ( size_t  n) [inline, static]

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) [inline, static]

Convert a number in Gray code encoding to a value.

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

pBuffer should be half the size of nHexSize

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

pBuffer should be half the size of nHexSize

static unsigned char GClasses::GBits::hexToByte ( char  lsn,
char  msn 
) [inline, static]

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) [inline, static]

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) [inline, static]

Convert little endian to a 16-bit native integer.

static short GClasses::GBits::littleEndianToN16 ( short  in) [inline, static]

Convert little endian to a 16-bit native integer.

static unsigned int GClasses::GBits::littleEndianToN32 ( unsigned int  in) [inline, static]

Convert little endian to a 32-bit native integer.

static int GClasses::GBits::littleEndianToN32 ( int  in) [inline, static]

Convert little endian to a 32-bit native integer.

static long long GClasses::GBits::littleEndianToN64 ( long long  in) [inline, static]

Convert little endian to a 64-bit native integer.

static unsigned long long GClasses::GBits::littleEndianToN64 ( unsigned long long  in) [inline, static]

Convert little endian to a 64-bit native integer.

static float GClasses::GBits::littleEndianToR32 ( float  in) [inline, static]

Convert little endian to a 32-bit native float.

static double GClasses::GBits::littleEndianToR64 ( double  in) [inline, static]

Convert little endian to a 64-bit native float.

static unsigned short GClasses::GBits::n16ToLittleEndian ( unsigned short  in) [inline, static]

Convert a 16-bit native integer to little endian.

static short GClasses::GBits::n16ToLittleEndian ( short  in) [inline, static]

Convert a 16-bit native integer to little endian.

static unsigned int GClasses::GBits::n32ToLittleEndian ( unsigned int  in) [inline, static]

Convert a 32-bit native integer to little endian.

static int GClasses::GBits::n32ToLittleEndian ( int  in) [inline, static]

Convert a 32-bit native integer to little endian.

static unsigned long long GClasses::GBits::n64ToLittleEndian ( unsigned long long  in) [inline, static]

Convert a 64-bit native integer to little endian.

static long long GClasses::GBits::n64ToLittleEndian ( long long  in) [inline, static]

Convert a 64-bit native integer to little endian.

static float GClasses::GBits::r32ToLittleEndian ( float  in) [inline, static]

Convert a 32-bit native float to little endian.

static double GClasses::GBits::r64ToLittleEndian ( double  in) [inline, static]

Convert a 64-bit native float to little endian.

static unsigned int GClasses::GBits::reverseEndian ( unsigned int  in) [inline, static]

Switch the endian of an unsigned integer.

static long long GClasses::GBits::reverseEndian ( long long  in) [inline, static]

Switch the endian of a double.

static float GClasses::GBits::reverseEndian ( float  in) [inline, static]

Switch the endian of a float.

static int GClasses::GBits::reverseEndian ( int  in) [inline, static]

Switch the endian of an integer.

static double GClasses::GBits::reverseEndian ( double  in) [inline, static]

Switch the endian of a double.

static unsigned long long GClasses::GBits::reverseEndian ( unsigned long long  in) [inline, static]

Switch the endian of a double.

static unsigned short GClasses::GBits::reverseEndian ( unsigned short  in) [inline, static]

Switch the endian of an unsigned integer.

static short GClasses::GBits::reverseEndian ( short  in) [inline, static]

Switch the endian of an unsigned integer.

static int GClasses::GBits::sign ( double  d) [inline, static]

Returns the sign of d.

static int GClasses::GBits::sign ( int  n) [inline, static]

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

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