Writing integer values to a file

Maviee

New Member
Hi,

I have the following problem: Lets say, I have an integer value like 0701010111 and want to write this value into a file. Afterwards I should find in the file something like "04 2D A8 13" (Hex value of above integer). To make the task even harder, the 4 bytes have to be in reverse byte order => "13 A8 2D 04".

Converting the int to the correct hex value is not the problem. My main problem to get the thing correctly into the file. I hope you can help:o

Thx in advance
Mav
 
why dont you do the whole activity of converting into a temp-table and read the temp-table in reverse to dump it into a file.
 
without know how you get the values into the file, I would probably try to make them strings first. then I will output them in a file.
 
The problem is neither to get my integer value into a hex-string or order the 4 Bytes in an array or TT. My problem is that I dont have a clue how to get the my string correctly into the file. If I do it the normal way like

put stream xyz unformatted
cMyHexString at 1.

then progress writes the values as ASCII in the file. Thats not what I want. I need the bytes the way they are in my string.

Greetings
Mav
 
If you have to put this integer in an existing file then you can load that file into a MEMPTR and then read/write the MEMPTR with get-byte put-byte.

Otherwise write the Bytes to a memptr and export the memptr to file like below.

Code:
DEFINE VARIABLE z AS MEMPTR.
SET-SIZE(z) = 4.
PUT-BYTE(z,1) = value first byte.
PUT-BYTE(z,2) = value second byte.
PUT-BYTE(z,3) = value third byte.
PUT-BYTE(z,4) = value fourth byte.
 
OUTPUT TO abc BINARY NO-CONVERT.
EXPORT z.
OUTPUT CLOSE.

This should get you on your way I suppose.

By the way, if you say:
Afterwards I should find in the file something like "04 2D A8 13"

You probably mean: if you look at the file with a hex editor, or not?
Otherwise I misunderstood your problem.


Regards,

Casper.
 
Thanks for this piece of code, now I more or less got it how to do it :)

As for your question with the hexeditor: Yes, if you look in the file with a hexeditor the integer value must be inverted like my little example.

Thanks a lot again :)

Greetings
Mav

Casper said:
If you have to put this integer in an existing file then you can load that file into a MEMPTR and then read/write the MEMPTR with get-byte put-byte.

Otherwise write the Bytes to a memptr and export the memptr to file like below.

Code:
DEFINE VARIABLE z AS MEMPTR.
SET-SIZE(z) = 4.
PUT-BYTE(z,1) = value first byte.
PUT-BYTE(z,2) = value second byte.
PUT-BYTE(z,3) = value third byte.
PUT-BYTE(z,4) = value fourth byte.
 
OUTPUT TO abc BINARY NO-CONVERT.
EXPORT z.
OUTPUT CLOSE.

This should get you on your way I suppose.

By the way, if you say:


You probably mean: if you look at the file with a hex editor, or not?
Otherwise I misunderstood your problem.


Regards,

Casper.
 
Back
Top