Binary Coded Decimal (BCD) Helper Functions

Functions

const char * rtBCDToString (OSUINT32 numocts, const OSOCTET *data, char *buffer, size_t bufsiz, OSBOOL isTBCD)
int rtStringToBCD (const char *str, OSOCTET *bcdStr, size_t bufsiz, OSBOOL isTBCD)
int rtStringToDynBCD (OSCTXT *pctxt, const char *str, ASN1DynOctStr *poctstr)
const char * rtTBCDToString (OSUINT32 numocts, const OSOCTET *data, char *buffer, size_t bufsiz)
int rtStringToTBCD (const char *str, OSOCTET *bcdStr, size_t bufsiz)

Detailed Description

Binary Coded Decimal (BCD) helper functions provide assistance in working with BCD numbers. Functions are provided to convert to a BCD values to and from string form.


Function Documentation

const char* rtBCDToString ( OSUINT32  numocts,
const OSOCTET *  data,
char *  buffer,
size_t  bufsiz,
OSBOOL  isTBCD 
)

This function converts a packed BCD value to a standard null-terminated string. Octet values may contain filler digits if the number of BCD digits is odd.

BCD digits can be 0(0000) to 9(1001). Filler digits can be A(1010), B(1011), C(1100), D(1101), E(1110) or F(1111)

Parameters:
numocts The number of octets in the BCD value.
data The pointer to the BCD value.
buffer The destination buffer. Should not be less than buffsiz argument is.
bufsiz The size of the destination buffer (in octets). The buffer size should be atleast ((numocts * 2) + 1) to hold the BCD to String conversion.
isTBCD Whether the input data is formatted as a TBCD string or not.
Returns:
The converted null-terminated string. NULL, if error has occurred or destination buffer is not enough.
See also:
rtTBCDToString
int rtStringToBCD ( const char *  str,
OSOCTET *  bcdStr,
size_t  bufsiz,
OSBOOL  isTBCD 
)

This function converts a standard null-terminated string into a BCD value. The source string should contain only characters '0' - '9', 'A' - 'F', or 'a' - 'f'. Otherwise, an error will occur.

Parameters:
str The source standard null-terminated string.
bcdStr The destination buffer. Should not be less than bufsiz is.
bufsiz The size of the destination buffer (in octets).
isTBCD Whether the string is a TBCD string or not.
Returns:
The number of octets in the resulting BCD value or a negative value if an error occurs.
See also:
rtStringToTBCD
int rtStringToDynBCD ( OSCTXT pctxt,
const char *  str,
ASN1DynOctStr *  poctstr 
)

This function converts a standard null-terminated string into a BCD value. The source string should contain only characters '0' - '9', 'A' - 'F', or 'a' - 'f'. Otherwise, an error will occur.

Parameters:
str The source standard null-terminated string.
pctxt Pointer to a context structure block.
poctstr Pointer to a dynamic octet string variable. Memory will be allocated for the data member of this structure with rtMemAlloc.
Returns:
The number of octets in the resulting BCD value or a negative value if an error occurs.
int rtStringToTBCD ( const char *  str,
OSOCTET *  bcdStr,
size_t  bufsiz 
)

This function converts a standard null-terminated string into a TBCD value. The source string should contain only characters '0' - '9', 'A' - 'F', or 'a' - 'f'. Otherwise, an error will occur. A TBCD string differs from a normal BCD string in that its bytes are flipped. The BCD string 0x12345f would be represented 0x2143f5 as a TBCD string.

Parameters:
str The source standard null-terminated string.
bcdStr The destination buffer. Should not be less than bufsiz is.
bufsiz The size of the destination buffer (in octets).
Returns:
The number of octets in the resulting BCD value or a negative value if an error occurs.
Since:
6.06
const char* rtTBCDToString ( OSUINT32  numocts,
const OSOCTET *  data,
char *  buffer,
size_t  bufsiz 
)

This function converts a packed TBCD value to a standard null-terminated string. Octet value can contain the filler digit to represent the odd number of BCD digits. A TBCD string differs from a normal BCD string in that the byte values of the octets are flipped. The BCD string 0x12345f would be represented 0x2143f5 as a TBCD string.

TBCD digits can be 0(0000) to 9(1001). Filler digits can be A(1010), B(1011), C(1100), D(1101), E(1110) or F(1111)

Parameters:
numocts The number of octets in the BCD value.
data The pointer to the BCD value.
buffer The destination buffer. Should not be less than buffsiz argument is.
bufsiz The size of the destination buffer (in octets). The buffer size should be atleast ((numocts * 2) + 1) to hold the BCD to String conversion.
Returns:
The converted null-terminated string. NULL, if error has occurred or destination buffer is not enough.
Since:
6.06