STTNet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Static Public Member Functions | List of all members
stt::data::BitUtil Class Reference

Responsible for conversion between binary data and strings. More...

#include <sttnet_English.h>

Static Public Member Functions

static std::string & bitOutput (char input, std::string &result)
 Convert a single character to its corresponding 8-bit binary string. More...
 
static std::string & bitOutput (const std::string &input, std::string &result)
 Convert each character in the string to binary bits and concatenate them into an overall string. More...
 
static char & bitOutput_bit (char input, const int pos, char &result)
 Get the pos-th bit (from left to right) of the character input (binary) and return '1' or '0'. More...
 
static unsigned long & bitStrToNumber (const std::string &input, unsigned long &result)
 Convert a "01" string (binary string) to an unsigned integer. More...
 
static unsigned long & bitToNumber (const std::string &input, unsigned long &result)
 Convert a string to binary and then to the corresponding numeric value. More...
 
static char & toBit (const std::string &input, char &result)
 Compress a "01" string of up to 8 bits into 1 byte (char). More...
 
static std::string & toBit (const std::string &input, std::string &result)
 Compress an arbitrary length "01" string into binary data, with every 8 bits as a byte. More...
 

Detailed Description

Responsible for conversion between binary data and strings.

Member Function Documentation

static std::string& stt::data::BitUtil::bitOutput ( char  input,
std::string &  result 
)
static

Convert a single character to its corresponding 8-bit binary string.

Parameters
inputInput character.
resultUsed to save the output binary string (e.g., 'A' -> "01000001").
Returns
Reference to result.
static std::string& stt::data::BitUtil::bitOutput ( const std::string &  input,
std::string &  result 
)
static

Convert each character in the string to binary bits and concatenate them into an overall string.

Parameters
inputInput string.
resultSave the output continuous bit string (length is input.size() * 8).
Returns
Reference to result.
static char& stt::data::BitUtil::bitOutput_bit ( char  input,
const int  pos,
char &  result 
)
static

Get the pos-th bit (from left to right) of the character input (binary) and return '1' or '0'.

Parameters
inputInput character.
posBit position (1~8, 1 is the most significant bit).
resultReturned bit character: '1' or '0'.
Returns
Reference to result.
static unsigned long& stt::data::BitUtil::bitStrToNumber ( const std::string &  input,
unsigned long &  result 
)
static

Convert a "01" string (binary string) to an unsigned integer.

Parameters
inputInput binary string (e.g., "1011").
resultOutput result value.
Returns
Reference to result.
static unsigned long& stt::data::BitUtil::bitToNumber ( const std::string &  input,
unsigned long &  result 
)
static

Convert a string to binary and then to the corresponding numeric value.

Parameters
inputAny original data string.
resultReturn the converted numeric value.
Returns
Reference to result.
Note
Actually calls bitOutput to get the bit string first, then converts it to an integer via bitStrToNumber.
static char& stt::data::BitUtil::toBit ( const std::string &  input,
char &  result 
)
static

Compress a "01" string of up to 8 bits into 1 byte (char).

Parameters
inputBinary string, up to 8 bits.
resultOutput compressed byte.
Returns
Reference to result.
static std::string& stt::data::BitUtil::toBit ( const std::string &  input,
std::string &  result 
)
static

Compress an arbitrary length "01" string into binary data, with every 8 bits as a byte.

Parameters
inputInput bit string (length should be a multiple of 8).
resultReturn the compressed binary data (each character represents 1 byte).
Returns
Reference to result.

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