Conversion Functions


Functions

unsigned fwCcpc_convertHexToDec (string pHex)
string fwCcpc_convertDecToHex (unsigned pDec)
dyn_char fwCcpc_convertHexToByte (string pHex)
string fwCcpc_convertByteToHex (dyn_char pByte)
dyn_char fwCcpc_convertDecToByte (unsigned pDec)
unsigned fwCcpc_convertByteToDec (dyn_char pByte)
unsigned fwCcpc_convertBinToDec (string pBin)
string fwCcpc_convertDecToBin (unsigned pDec)
dyn_char fwCcpc_convertWordsToBytes (dyn_uint pInt, int width)
dyn_uint fwCcpc_convertBytesToWords (dyn_char pChar, int width)
float fwCcpc_convertHexToFloat (string pHex)
string fwCcpc_convertFloatToHex (float pDec)
bool fwCcpc_isHex (string pHex)
bool fwCcpc_isBin (string pBin)

Detailed Description

A 'number' can have various representations: an array of characters in a textfield on a panel (string), a number stored in a variable (unsigned) or an array of bytes (dyn_char) where each char holds a byte. In order to facilitate the various conversions e.g. from the panel's string to the required input parameter (mostly a byte stream), a set of conversion functions is provided.

Function Documentation

unsigned fwCcpc_convertBinToDec ( string  pBin  ) 

This function converts a binary number (represented as a string) to the corresponding decimal number (unsigned integer).

Parameters:
[in] pBin binary number to be converted.
Returns:
unsigned decimal number.
Example:

  (...)
  unsigned result;

  result = fwCcpc_convertBinToDec("101110101011");   // convert binary number '101110101011' to the corresponding decimal number
  DebugTN("Decimal: " + (string) result);   // output the result of the conversion
  (...)



dyn_uint fwCcpc_convertBytesToWords ( dyn_char  pChar,
int  width 
)

This function converts an array of Bytes to an array of Words (Integers). The actual buswidth (wordsize) can be specified.

Parameters:
[in] pChar array of bytes to be converted.
[in] width specifies the number of bytes to build up a word (buswidth).
Returns:
dyn_uint array of unsigned integers.
Example:

  (...)
  dyn_uint data;
  dyn_char myData;

  fwCcpc_LBUSRead("pclbcecs03",0x1000020,FWCCPC_LBUS_BITS_32,3,myData) // reads bytestream into myData
  data = fwCcpc_convertBytesToWords(myData,4);   // convert bytes array to an array of integers
  (...)



unsigned fwCcpc_convertByteToDec ( dyn_char  pByte  ) 

This function converts byte(s) to the corresponding decimal number.

Parameters:
[in] pByte byte(s) to be converted.
Returns:
unsigned decimal number.
Example:

  (...)
  unsigned result;

  result = fwCcpc_convertByteToHex(makeDynChar(41, 42, 43));   // convert bytes '41', '42' & '43', to the corresponding decimal number
  DebugTN("Decimal: " + result);   // output the result of the conversion
  (...)



string fwCcpc_convertByteToHex ( dyn_char  pByte  ) 

This function converts byte(s) (as received from the hardware) to the corresponding hexadecimal number (e.g. textfield on a panel). The first byte becomes the most significant in the hex string.

Parameters:
[in] pByte byte(s) to be converted.
Returns:
string hexadecimal number.
Example:

  (...)
  string result;

  result = fwCcpc_convertByteToHex(makeDynChar(255, 15, 0));   // convert bytes '255', '15' & '0', 
                                                             // to the corresponding hexadecimal number which reads 'FF0F00'.
  DebugTN("Hexadecimal: " + result);   // output the result of the conversion represented as a string
  (...)



string fwCcpc_convertDecToBin ( unsigned  pDec  ) 

This function converts an unsigned integer to the corresponding binary representation (string).

Parameters:
[in] pDec decimal number to be converted.
Returns:
string binary number.
Example:

  (...)
  string result;

  result = fwCcpc_convertDecToBin(1127);   // convert decimal number '1127' to the corresponding binary number
  DebugTN("Binary: " + result);   // output the result of the conversion
  (...)



dyn_char fwCcpc_convertDecToByte ( unsigned  pDec  ) 

This function converts an decimal number to the corresponding byte(s).

Parameters:
[in] pDec decimal number to be converted.
Returns:
dyn_char byte(s).
Example:

  (...)
  dyn_char result;

  result = fwCcpc_convertDecToByte(1127);   // convert decimal number '1127' to the corresponding byte(s)
  DebugTN("Bytes: " + result);   // output the result of the conversion
  (...)



string fwCcpc_convertDecToHex ( unsigned  pDec  ) 

This function converts an unsigned integer to the corresponding hexadecimal representation as a string.

Parameters:
[in] pDec decimal number to be converted.
Returns:
string hexadecimal number.
Example:

  (...)
  string result;
  unsigned number = 1127;

  result = fwCcpc_convertDecToHex(number);   // convert decimal number '1127' to the corresponding hexadecimal string representation
  DebugTN("Hexadecimal: " + result);   // output the result of the conversion
  (...)



string fwCcpc_convertFloatToHex ( float  pDec  ) 

This function converts a real number to the corresponding hexadecimal number. These functions are aimed to get a simple way to do arithmetic operations from large registers (48 bit counters). (C) provided and used by Herve Chanal, LPC Clermont Ferrand.

Parameters:
[in] pDec real number to be converted.
Returns:
string hexadecimal number.
Example:

  (...)
  string result;

  result = fwCcpc_convertFloatToHex(1127);   // convert decimal number '1127' to the corresponding hexadecimal number
  DebugTN("Hexadecimal: " + result);   // output the result of the conversion
  (...)



dyn_char fwCcpc_convertHexToByte ( string  pHex  ) 

This function converts an hexadecimal number (represented as a string) to the corresponding array of byte(s). Each byte is represented as a char. A byte stream is regularly used as input or output of the fwCcpc framework. (e.g. writing or reading memory blocks) When debugging in the PVSS PARA module you are prompted the ASCII representation of the byte value. The array starts with the most significant byte.

Parameters:
[in] pHex hexadecimal string to be converted.
Returns:
dyn_char byte(s).
Example:

  (...)
  dyn_char result;

  result = fwCcpc_convertHexToByte("ff00");   // convert hexadecimal string representation ('ff00') 
                                            // to the corresponding byte(s): '255' & '0'
  DebugTN("Byte(s): " + result);   // output the result of the conversion
  (...)



unsigned fwCcpc_convertHexToDec ( string  pHex  ) 

This function converts a string representing a hexadecimal number (e.g. text on panel) into the corresponding decimal number (unsigned integer).

Parameters:
[in] pHex hexadecimal number to be converted.
Returns:
unsigned decimal number.
Example:

  (...)
  unsigned result;

  result = fwCcpc_convertHexToDec("24e7d");   // convert hexadecimal string representation ('24e7d') to the corresponding decimal number
  DebugTN("Decimal: " + (string) result);   // output the result of the conversion
  (...)



float fwCcpc_convertHexToFloat ( string  pHex  ) 

This function converts an hexadecimal number to the corresponding real number. It is based on the fwCcpc_convertHexToDec(string pHex) function. These functions are aimed to get a simple way to do arithmetic operations from large registers (48 bit counters). (C) provided and used by Herve Chanal, LPC Clermont Ferrand

Parameters:
[in] pHex hexadecimal number to be converted. Note: if the hexadecimal number is invalid then the returned value will be zero (0).
Returns:
float number.
Example:

  (...)
  float result;

  result = fwCcpc_convertHexToFloat("24e7d");   // convert hexadecimal number '24e7d' to the corresponding float number
  DebugTN("Float: " + (string) result);   // output the result of the conversion
  (...)



dyn_char fwCcpc_convertWordsToBytes ( dyn_uint  pInt,
int  width 
)

This function converts an array of Words (Integers) to an array of Bytes. The actual buswidth (wordsize) can be specified.

Parameters:
[in] pInt integer array to be converted.
[in] width number of bytes (out of 4) to be used in conversion.
Returns:
dyn_char array of bytes.
Example:

  (...)
  dyn_char data;
  string result;

  data = fwCcpc_convertWordsToBytes(makeDynInt(0xfeedbabeu,0x12345678u),4);   // convert integer array to an array of bytes
  //fwCcpc_write(makeDynString("myBoard1.myReg01"), makeDynChar(data), ...)
  result = fwCcpc_convertByteToHex(data);  // gives 'FEEDBABE12345678'
  (...)



bool fwCcpc_isBin ( string  pBin  ) 

This function checks if the specified binary number is valid or not.

Parameters:
[in] pBin binary number.
Returns:
true the number is a valid binary number.

false the number is not a valid binary number.

Example:

  (...)
  if (fwCcpc_isBin("1101011101"))   // check if the binary number '1101011101' is valid
     DebugTN("The number is a valid binary number");
  else
     DebugTN("The number is not a valid binary number");
  (...)



bool fwCcpc_isHex ( string  pHex  ) 

This function checks if the specified hexadecimal number is valid or not.

Parameters:
[in] pHex hexadecimal number.
Returns:
true the number is a valid hexadecimal number.

false the number is not a valid hexadecimal number.

Example:

  (...)
  if (fwCcpc_isHex("24e7d"))   // check if the hexadecimal number '24e7d' is valid
     DebugTN("The number is a valid hexadecimal number");
  else
     DebugTN("The number is not a valid hexadecimal number");
  (...)




Generated on Fri Mar 28 13:15:39 2008 for FwCcpc by  doxygen 1.4.7