Subj : IEEE-754 and Borland C5.2 issue To : borland.public.cpp.borlandcpp From : schears@hotpop.com (GooglePoster) Date : Thu Sep 04 2003 01:49 pm Hello, I wish to be able to use Borland C++5.2 to create a 16 bit DOS application that reads IEEE-754 data in hex format and compares it to a decimal value, and then convert the decimal value back into IEEE-754. I can do this under Microsoft VisualC++ 6.0 by creating a DOS app, but find out that Borland has some restrictions that I can not seem to work around. In ConvertDataFrame() the right shift by 24 causes the ASCII value to be placed into the buffer, versus the actual raw hex value. Any suggestions? Thank you, A copy of the code appears: #include unsigned char Buffer[] = {0,0,0x80,0x3f,0,0,0xc8,0x42}; unsigned char TestBuffer[9]; void ConvertData(void); void ConvertDataFrame(void); char MatchFound = 0; long Min = 1, Max = 100; float FloatMin, FloatMax; union RANGE_CONVERT { float RangeValue; #ifdef __BORLANDC__ long IntData; #else int IntData; #endif } ; //union RANGE_CONVERT var2; // C declaration of a union variable //RANGE_CONVERT var3; // C++ declaration of a union variable #ifdef __BORLANDC__ union RANGE_CONVERT RangeMin; union RANGE_CONVERT RangeMax; #else RANGE_CONVERT RangeMin; RANGE_CONVERT RangeMax; #endif int main() { ConvertData(); FloatMin = (float)Min; FloatMax = (float)Max; if ((RangeMin.RangeValue == FloatMin) && (RangeMax.RangeValue == FloatMax)) MatchFound = 1; ConvertDataFrame(); return(1); } void ConvertData() { RangeMin.IntData = 0; RangeMin.IntData = ((long)Buffer[3] << 24); RangeMin.IntData |= ((long)Buffer[2] << 16); RangeMin.IntData |= ((long)Buffer[1] << 8); RangeMin.IntData |= ((long)Buffer[0]); //RangeMin.IntData = 3f800000 RangeMax.IntData = 0; RangeMax.IntData = ((long)Buffer[7] << 24); RangeMax.IntData |= ((long)Buffer[6] << 16); RangeMax.IntData |= ((long)Buffer[5] << 8); RangeMax.IntData |= ((long)Buffer[4]); //RangeMax.IntData = 42c80000 return; } void ConvertDataFrame() { TestBuffer[0] = (unsigned char)(RangeMin.IntData); TestBuffer[1] = (unsigned char)(RangeMin.IntData >> 8); TestBuffer[2] = (unsigned char)(RangeMin.IntData >> 16); // Borland causes this value to be placed as an ASCII character(0x3f = '?') in to the buffer...WHY? TestBuffer[3] = (unsigned char)(RangeMin.IntData >> 24); TestBuffer[4] = (unsigned char)(RangeMax.IntData); TestBuffer[5] = (unsigned char)(RangeMax.IntData >> 8); TestBuffer[6] = (unsigned char)(RangeMax.IntData >> 16); // Borland causes this value to be placed as an ASCII character(0x42 = 'B') in to the buffer...WHY? TestBuffer[7] = (unsigned char)(RangeMax.IntData >> 24); return; } .