Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting Hex data out of a file into a string
Message
From
18/10/2000 18:39:43
 
 
To
18/10/2000 18:14:50
Josh Fedke
National Financial Corporation
Milwaukee, Wisconsin, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00431199
Message ID:
00431234
Views:
10
Hi!

Why you use 'Allt(str(asc(' for fread??? fread already returns data you need. They will be binary data in the VFP character string. VFP character strin can contain eny codes include zero code (Zero byte don't cause VFP string to finish). So feel free to use VFP character strings to store any binary data - be sure data will not be corrupted.

Following is my edition of your sample:

bytes = fread(f_hand,2)
Number = ascc(left(pcValue,1)) + ;
asc(substr(pcValue,2,1))*256

You need nothing else!

HTH.


>I guess this is more of an annoyance. Here is an example sequence.
>
>ideal:
>file data = 2C01
>flip = 0x012C = 300 decimal
>
>foxpro:
>file data = 2C01
>lower_byte = alltrim(str(asc(fread(f_hand,1))))
>upper_byte = alltrim(str(asc(fread(f_hand,1))))
>
>upper_byte and lower_byte are now integers because fread() interprets them as characters which I convert to their ascii equivalents.
>
>convert uppper_byte and lower_byte *BACK* to to Hex values!
>
>(Notice I can't swap here becase 0144 != 300 because the hex value is stored as an upper and lower byte.)
>
>hex_val = upper_byte + lower_byte (this is the swap)
>evaluate("0x" + hex_val)
>
>AARGH!
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform