Einzelnen Beitrag anzeigen

enzo

Registriert seit: 3. Feb 2006
16 Beiträge
 
#2

Re: Von c++ nach delphi Float Converter

  Alt 8. Feb 2006, 23:16
Folgendes interessiert mich das es ihn delphi uebersetzt wird


[c]void CFloatCnvtDlg::OnKillfocusHexEdit()
{
UINT nType;
int iLen, iCnt, iDataCtr;
unsigned char bData;

// Make a union of a float and it's four bytes.
union FloatHex{
unsigned char uData[4]; // Four bytes to hold an IEEE 754 float
float fValue; // The IEEE 754 float
}uConvert;

// Declare a string variable to hold the ASCII HEX form, and temp byte buffer.
CString strHex, strByte;


// Read user entered string from the Hex edit box.
m_HexEdit.GetWindowText(strHex);

// Convert HEX string to uppercase before conversion.
strHex.MakeUpper();

// Check for proper length of HEX string before conversion.
iLen = strHex.GetLength();

// Error checking - Check for invalid hex values.
// Display standard message box if non-Hex char found.
if (iLen == 8) {
for (iCnt=0; iCnt<iLen; ++iCnt){
bData = strHex.GetAt(iCnt);
if ( bData < '0' || (bData > '9' && bData < 'A') || bData > 'F' )
{
CString strCaption;
strCaption = "Bad Info";
nType = MB_ICONERROR;
CString strMsgText = "Please enter valid HEX string only.";
MessageBox( strMsgText, strCaption, nType); // Show msg box

// Setting iLen to -1 stops this loop and disables conversion.
iLen = -1;
}
}
}

// Conversion of ASCII Hex string to hex bytes.
if (iLen == 8) // MUST be 8 chars. (2 chars per byte, 4 bytes per float.)
{
//Loop through the HEX chars, and convert to byte values
//Because we read the float HEX string MSB to LSB, we must store
//the data MSB to LSB. So, iDataCtr was created to help readability.
iDataCtr = (iLen / 2) - 1; //2 text chars per HEX byte. (0-based counter)

for (iCnt=0; iCnt<iLen; ++iCnt){
//Read high nibble char & store
bData = strHex.GetAt(iCnt); //Read high nibble char from string
if (bData > '9') //Convert ASCII A-F to decimal 10-15
bData -= 7;
bData <<= 4; //move to high nib & store
uConvert.uData[iDataCtr] = bData;

// Get low nibble (next char in string)
++iCnt; //inc char ptr
bData = strHex.GetAt(iCnt); //get next char (low nibble)
if (bData > '9') //Convert ASCII A-F to decimal 10-15
bData -= 7;
bData -= '0'; //convert from ASCII to hex
uConvert.uData[iDataCtr] |= bData;//merge hex value

--iDataCtr; //dec data union ptr
}
m_Float = uConvert.fValue; // Update the float edit variable
UpdateData(FALSE); // Update the dialog box (calls DDX).
}
// Error reporting. Skip this if an invalid Hex value was entered. (marked by iLen = -1)
else if (iLen != -1) {
// If we got here, either more than 8 or less than 8 chars were entered.
CString strCaption;
if (iLen < 8) { // Show msg for less than 8 chars
strCaption = "Not Enough Info";
nType = MB_ICONEXCLAMATION;
}
if (iLen > 8) { // Show msg for more than 8 chars
strCaption = "Too Much Info!";
nType = MB_ICONQUESTION;
}
CString strMsgText = "Please enter 4 Hex bytes";
MessageBox( strMsgText, strCaption, nType); // Show msg box
}

}





Ich hoffe Ihr koennt mir Helfen


Gruss enzo
  Mit Zitat antworten Zitat