Advertisement

find a values position within a binary file

Started by April 07, 2005 04:40 PM
6 comments, last by Winograd 19 years, 5 months ago
lets say i have a 4 byte word as 0xAAFF, how would i find the position where 0xAAFF is (as in offset from 0)?
Quote: Original post by Genjix
lets say i have a 4 byte word as 0xAAFF, how would i find the position where 0xAAFF is (as in offset from 0)?


you need to load in the file (stream until EOF) and then search for the value, keeping track of how many bytes/words you have already read (for the offset).

EDIT: thougth this was in a programming forum :( unix i believe has tools for it (dump or cmp or something). Sorry dont know for sure.

HTH
Advertisement
hmmmm, if I don't get any answers will someone tell me how to convert a hex value to an int? (stl is fine)
Quote: Original post by Genjix
hmmmm, if I don't get any answers will someone tell me how to convert a hex value to an int? (stl is fine)

int foo = 0xAAFF; // ?
Use ftell(f) ? It gives the current position in the file.
:P i meant a string, so I can do byteposition 0xAFFF
how would i convert this string to an int? (lexical_cast?)
Advertisement
its ok, i've made 2 lightweigth c programs to do it now.
Stupid side note: 0xAAFF is 2 bytes, not 4..

This topic is closed to new replies.

Advertisement