BBS: Inland Empire Archive Date: 05-23-92 (18:40) Number: 190 From: ROB FLOR Refer#: NONE To: DICK DENNISON Recvd: NO Subj: Re: MBIN Conf: (2) Quik_Bas
DD>RF>Do you know how to pack a number the old MKS$ way? DD>RF>I need to write QWK xxx.NDX files in Microsoft Binary Format, which >RF>isn't supported by PDQ. DD>RF>It is integers which need to be packed. I have a conversion routine >RF>in a write only language, I can't make it out. DD>I used to be able to reed C <g>; post the code and I'll see if I can >port it. /*** MSBIN conversion routines ***/ union Converter { unsigned char uc[10]; unsigned int ui[5]; unsigned long ul[2]; float f[2]; double d[1]; } /* MSBINToIEEE - Converts an MSBIN floating point number */ /* to IEEE floating point format */ /* */ /* Input: f - floating point number in MSBIN format */ /* Output: Same number in IEEE format */ float MSBINToIEEE(float f) { union Converter t; int sign, exp; /* sign and exponent */ t.f[0] = f; /* extract the sign & move exponent bias from 0x81 to 0x7f */ sign = t.uc[2] / 0x80; exp = (t.uc[3] - 0x81 + 0x7f) & 0xff; /* reassemble them in IEEE 4 byte real number format */ t.ui[1] = (t.ui[1] & 0x7f) | (exp << 7) | (sign << 15); return t.f[0]; } /* End of MSBINToIEEE */ /* IEEEToMSBIN - Converts an IEEE floating point number */ /* to MSBIN floating point format */ /* */ /* Input: f - floating point number in IEEE format */ /* Output: Same number in MSBIN format */ float IEEEToMSBIN(float f) { union Converter t; int sign, exp; /* sign and exponent */ t.f[0] = f; /* extract sign & change exponent bias from 0x7f to 0x81 */ sign = t.uc[3] / 0x80; exp = ((t.ui[1] >> 7) - 0x7f + 0x81) & 0xff; /* reassemble them in MSBIN format */ t.ui[1] = (t.ui[1] & 0x7f) | (sign << 7) | (exp << 8); return t.f[0]; } /* End of IEEEToMSBIN */ Thanks - and good luck! Rob * OLX 2.2 * One good turn gets all the blankets. --- WM v2.01/91-0156 * Origin: BEAR HEAVEN BBS (914) 677-6948 MILLBROOK NY (1:272/53)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET