Converting Obcds - Casio ClassPad 300 Programming Manual

Sdk programming guide
Hide thumbs Also See for ClassPad 300:
Table of Contents

Advertisement

These functions also return an error code and place the result in x.

Converting OBCDs

There are also several functions that convert OBCDs into different data types. An OBCD
can be converted to a short, long or string. The functions to convert an OBCD to a short
or long are similar to the functions we've already seen:
word
Cal_toshort_OBC(OBCD *x, short *wx); //Convert an OBCD to a short
word
Cal_tolong_OBC(OBCD *x, long *wx);
Once again, be careful not to expect the conversion as the return value:
OBCD x;
long y;
word error_code;
Cal_setn_OBC(6, &x);
error_code = Cal_tolong_OBC(&x, &y);
There are many different functions that can be used to convert an OBCD to a string.
These functions differ by which form of the OBCD is placed in the string – normal mode,
scientific notation, etc. We will look at four of these functions. To view all of the
available functions, refer to the ClassPad 300 SDK API Reference Guide Strings-
>Functions to Convert OBCD/CBCD datatypes to strings.
//Changes the OBCD value to normal mode and places it in str.
word
CP_Norm_OBC (OBCD *x, CP_CHAR str[], short mode);
//Changes decimal portion of OBCD to fixed size and places it in str
word
CP_Fix_OBC (OBCD *x, CP_CHAR str[], short dig);
// Changes the OBCD value to scientific notation of precision dig and
// places it in str.
word
CP_Sci_OBC (OBCD *x, CP_CHAR str[], short dig);
// Change an OBCD object to a 15 digit string in normal mode.
word
CP_15digit_OBC (OBCD *x, CP_CHAR str[]);
Here is an example on how to convert an OBCD to a string in different forms:
OBCD x;
CP_CHAR buffer[15];
Cal_setn_OBC(1525, &x);
x.obcd1.exponential = 0x1001;
CP_15digit_OBC(&x, buffer);
CP_Norm_OBC(&x, buffer, IM_MODE_NORM1);
CP_Fix_OBC(&x, buffer, 4);
CP_Sci_OBC(&x, buffer, 4);
//Convert an OBCD to a long.
// set x = 6
// set y = x;
// set x = 1525
// puts 15.25 in buffer
// puts 15.25 in buffer
// puts 15.2500 in buffer
// puts 1.525e1 in buffer
90

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents