Jump to content
  • Advertisement

Archived

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

gimp

Endian Flip

This topic is 6203 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''m attempting to grab a number from a big endian data stream like this:
  
inline const unsigned int CLightwaveModel::GetU4(void)
{
	//Advance the index

	m_DataIndex += sizeof(unsigned int);

	//Return the value

	return 	(((char)m_Data[m_DataIndex-4]<<24)
 		    +((char)m_Data[m_DataIndex-3]<<16)
		    +((char)m_Data[m_DataIndex-2]<<8)
			+(char) m_Data[m_DataIndex-1]);	
}
  
However I can''t seem to work out the exact syntax. I see the data like this: 00 00 01 90 A quick check in calc tells me this is 400 in decimal, which is the number I expected to get. When I run my code the above function returns 144. Can anyone see anything silly in my code? Many thanks Chris Brodie http:\\fourth.flipcode.com

Share this post


Link to post
Share on other sites
Advertisement
When you shift, you run right out of the bounds of the char...
90 in hex is your 144 in decimal, all the other hex values are shifted out of existance.

Try this (I think):
( (unsigned int)((char)m_Data[m_DataIndex-4])<<24 )

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!