Finally, if you want to convert from an int, long, short or char to a HEX string, use
these functions:
CP_CHAR *CP_IntToStringHex(int value, CP_CHAR *pS);
CP_CHAR *CP_LongToStringHex(long value, CP_CHAR *pS);
CP_CHAR *CP_ShortToStringHex(short value, CP_CHAR *pS);
CP_CHAR *CP_CharToStringHex(char value, CP_CHAR *pS);
Here is an example that uses some of these functions:
CPString str1("44");
int i = CP_StringToInt((CP_CHAR*)str1.GetBuffer()); // i=44
CP_CHAR c[100];
CP_IntToString(54, c); // c=”54”
CP_IntToStringHex(15, c); // c=”0000000F”
Converting Between CPStrings and BCDs
The ClassPad does not have native support for doubles. Instead the ClassPad uses its
own data type called the BCD to represent floating point numbers. BCDs and their
internal representation are discussed in detail in the section titled Using Floating-Point
Values with the ClassPad.
Because a BCD can have several different visual representations (scientific, normal, fixed,
etc) there are several different functions to convert a BCD to a string. There are also
usually pairs of functions: one that works with OBCD (real numbers) and another that
works with CBCD (complex numbers).
To take the internal representation of a BCD in hex, and place it in a string use:
word CP_codech_OBC(CP_CHAR data[], OBCD *x);
To convert a BCD to normal mode use:
word CP_Norm_OBC(OBCD *x,CP_CHAR str[],short mode);
word CP_Norm_CMP(CBCD *x,CP_CHAR str[],short mode);
The parameter mode represents which normal mode you would like to use. Valid options
are IM_MODE_NORM1 or IM_MODE_NORM2.
To convert a BCD to a fixed size use:
word CP_Fix_OBC(OBCD *x,CP_CHAR str[],short dig);
word CP_Fix_CMP(CBCD *x,CP_CHAR str[],short dig);
where dig is the number of digits to the right of the decimal. For example 5 with a fixed
size of 3 would be 5.000.
To create a string representation of a BCD in scientific notation use:
word CP_Sci_OBC(OBCD *x,CP_CHAR str[],short dig);
word CP_Sci_CMP(CBCD *x,CP_CHAR str[],short dig);
103