Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating binary file
Message
 
 
To
20/03/1998 10:49:34
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00085981
Message ID:
00086003
Views:
48
Mark,

Here's a set of routines I use to handle calls in and out of various API functions:

* ConvertAPI.prg 08-Oct-97 

* these functions convert to/from internal binary storage

function ToWord( pnNumber )
nMSB = int( pnNumber / 256 )  && most significant byte
nLSB = pnNumber % 256  && least significant byte
return chr( nLSB ) + chr( nMSB )

function ToLong( pnNumber )
nMSW = int( pnNumber / 65536 )  && most significant word
nLSW = pnNumber % 65536  && least significant word
return ToWord( nLSW ) + ToWord( nMSW )

function FromWord( pcBuffer )
return asc( substr( pcBuffer, 2, 1 ) ) * 256 + asc( left( pcBuffer, 1 ) )

function FromLong( pcBuffer )
return FromWord( substr( pcBuffer, 3, 2 ) ) * 65536 + FromWord( left( pcBuffer, 2 ) )


If you are using the Long functions a lot (thousands of times in a loop), significant perfomance can be gained by "inlining" the Word functions.

>The real problem is how would I convert numbers to 4-byte integers. An example is converting a value of 22030 to be 00 00 56 0E.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform