Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Well, the thing is that in Linux with the Terminal I use nano to create a plain text file with the content "GIF89a2017" and I save it as rare and I know that due to that header the file is detected as a GIF image. The thing is that four bytes that I put next to the header, 2017 in this case, give the resolution. That way when I do the command file rare it outputs: rare.gif: GIF image data, version 89a, 12338 x 14129.

What I have tried:

I know that those four bytes are some unsigned 16-bit integers but I don't know how it is done to convert 20 into 0x3032 and 17 into 0x3731. That way you get the resolution but I don't know how you get it, to me it just seems like a 3 is added.

Thanks to everyone!
Posted
Updated 19-Oct-17 9:35am

1 solution

0x3032 is the hex representation of the characters '02' stored in a short. And (assuming this is on an x86 system) that will actually be seen as the two characters '20' when addressed as bytes. Similarly 0x3731 is the characters 71, or 17 in normal order.

To store those two values as integers you need to put 20 as hex 0x0014) and 17 as hex 0x0011. So your header needs to be "GIF89a\x00\x14\x00\x11"; where the \x prefix indicates an absolute hex value not the four character \x00 etc.. But quite how you expect to create a GIF image with a text editor is something that you may find even more challenging.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900