Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

prh99

Binary question..

This topic is 5730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writting a program that allows me to modify IFF files (archive format used by EA). I think the MSB is in the opposite position. For example, One of the values in the header of the file I testing my program with is suppose to be 0x3228 but I get 0x2832 (the location is stored as a 32 bit integer). I was wondering what the quickest way to flip the bits would be. Thanks Edit: Sorry I made a mistake the values should be 0x28320000 and 0x00003228. I don't know why I forgot the zeros. The file format was developed on Apple so all the numbers are stored in Motorola format. [edited by - prh99 on April 2, 2003 1:55:20 PM]

Share this post


Link to post
Share on other sites
Advertisement
if 3228 gets rewritten to 2832 its either not an int or its just coincedce tjhey are flipped. i think the most likely thing is its stored as a string of four chars.
if it is an integer, but these numbers were just examples, i would read the 2 high and 2 low bytes seperatly as words, and then do something like this: (syntax probably not correct though, just started with c++)

>> low //get words from stream
>> high
myint = ((int)high << 16) | (int)low // << is the bitshift operator in c++, not?

Share this post


Link to post
Share on other sites
yeaqh it is, I agree. i recon its 16 bits integer, or string manipulation. I can''t see why itwould be shifted that way.

I would definitely say its a 16 bit integer. I doubt it is a string, cuz then it would return asci values, and it wouldnt be null terminated.

Share this post


Link to post
Share on other sites
Looks like the files are stored in little-endian format.

If it is a 16bit value, stored in a 16bit short, you can rotate 8 bits to reverse the order...


short myVal = 0x2832;

asm ror myVal, 8; // _asm in VC++, I think.

myVal would now be 0x3228.


If you''re storing them in a 32bit variable, you can read them in one byte at a time...

long myVal = 0;

myVal = (long)( file.get() | (file.get() << 8) );

Share this post


Link to post
Share on other sites
quote:
Edit: Sorry I made a mistake the values should be 0x28320000 and 0x00003228. I don''t know why I forgot the zeros. The file format was developed on Apple so all the numbers are stored in Motorola format.



Ok then change that second method I showed to...

long myVal = 0;

myVal = (long)( file.get() | (file.get() << 8) | (file.get() << 16) | (file.get() << 24) );

That should work.

Share this post


Link to post
Share on other sites
Thanks guys.

<< is right shift correct?

if it was used one time on the binary value 10011001 the result would 01001100 right?

Share this post


Link to post
Share on other sites
<< left shift.
>> right shift.


quote:
if it was used one time on the binary value 10011001 the result would 01001100 right?


Yes this part is correct, for a right shift.

Share this post


Link to post
Share on other sites
quote:
Original post by Xanth
<< left shift.
>> right shift.


[quote]if it was used one time on the binary value 10011001 the result would 01001100 right?


Yes this part is correct, for a right shift.

Okay thanks, it works.

Share this post


Link to post
Share on other sites
stupid question maybe, but makes the prefix ''0x'' a number hexadecimal in c++?

Share this post


Link to post
Share on other sites
quote:
Original post by Eelco
stupid question maybe, but makes the prefix '0x' a number hexadecimal in c++?


No it's not stupid. Yes 0x prefix marks a number as hex in C and C++.


[edited by - prh99 on April 2, 2003 2:31:24 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!