#### Archived

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

# 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.

## 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 on other sites
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 )

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631786
• Total Posts
3002350
×