BBS: Inland Empire Archive Date: 06-02-92 (19:20) Number: 81 From: JEFF FREEMAN Refer#: NONE To: ROB FLOR Recvd: NO Subj: Mbin Conf: (2) Quik_Bas
RF>MH>If you still need conversion from the old Microsoft RF>MH>Binary Format for use >in > >PDQ, PDS and QB 4.x have built in conversion with > >MKSMBF, MKDMBF, CVSMBF, > >CVDMDF. Looks like it would have to be a pre-PDQ conversion though. RF> It's me who is looking for an explaination of the format, and its to >convert to the old Microsoft Binary Format, not from. RF> I've wracked my books looking for a description which I'd seen >somewhere, and am hopeing someone on the echo will have something in a >reference book. It probably wouldn't be in a QB reference since it's a >built in function, but a general programmers reference. RF> Someone at Cresent knows how to pack a number in MSBIN since they >added CVIMKS$ two months after I bought PDQ 2.2 (HINT HINT). :) Single$ = MKSMBF$(x) Double$ = MKDMBF$(x) If 'x' is a different variable type than SINGLE or DOUBLE, it is first converted by QB to a single (for MKSMBF$) or a double (for MKDMBF$). So use MKSMBF$ for single and integer variables, use MKDMBF$ for double and Long-integer variables. *OR* you can enter the QB environ' with the /MBF command line parameter - this will make QB use the old MSBIN format instead of IEEE. I.E. MKS$, MKD$, CVS, CVD, will do what you want them to do. If you absolutely have to write your own routine to do this, use this: /*** MSBIN conversion routines ***/ union Converter { unsigned char uc[10]; unsigned int ui[5]; unsigned long ul[2]; float f[2]; double d[1]; } 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 */ 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 */ 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 */ Knock yourself out. --- * Origin: Camelot BBS - Dallas, TX - (214) 339-8283 (1:124/1011)
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