AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Von c++ nach delphi Float Converter

Von c++ nach delphi Float Converter

Ein Thema von enzo · begonnen am 8. Feb 2006 · letzter Beitrag vom 8. Feb 2006
Antwort Antwort
enzo

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

Von c++ nach delphi Float Converter

  Alt 8. Feb 2006, 22:51
Da der Converter den ich beigefuegt habe Ihn C++ geschrieben und Ich kein Spezialist bin.

Da Ich serielle Daten empfange und mit der Funktion Hex in Float Umwandeln muss.

Habe das Programm in C++ probiert und es gibt mir die Richtigen Werte.

Wer Kann mir Helfen.

Danke ihm voraus

Gruss enzo
Angehängte Dateien
Dateityp: zip floatconvert_149.zip (36,9 KB, 8x aufgerufen)
  Mit Zitat antworten Zitat
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
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz