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 17:50:41
 
 
To
18/10/2000 17:42:59
Josh Fedke
National Financial Corporation
Milwaukee, Wisconsin, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00431199
Message ID:
00431200
Views:
13
See code below. You can easy adjust it to any size of integer. These are unsigned integer routines.
********************************************************************
procedure IntToSTR
lparameters pnValue
return chr(pnValue % 256) + ;
     chr(int(pnValue / 256) % 256) + ;
     chr(int(pnValue / 65536) % 256) + ;
     chr(int(pnValue / 16777216) % 256 )
**********************************************
procedure STRToInt
lparameters pcValue
return asc(left(pcValue,1)) + ;
     asc(substr(pcValue,2,1))*256 + ;
     asc(substr(pcValue,3,1))*65536 + ;
     asc(substr(pcValue,4,1))*16777216
>I'm trying to get the size of a image file using the bytes in the header. What I can't seem to negotiate is that fgets() translates the bytes it pulls from the file into their ASCII equivalent.
> I just want the the hex values because I need to swap an upper and lower byte (endianess?) before doing evaluate("0x" + hex_size). In C/C++ you can change the stream extraction type or cast the extracted values. Can Foxpro do something like this, so that hex values can be extracted from a file?
> Also, " alltrim(str(asc(fgets(file_handle,1)))) " doesn't work because when hex A-F appear, fgets doesn't convert them to a valid ASCII character and then " alltrim(str(asc( " won't work correctly. Thanks in advance.
>
> -Josh
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