Content: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Background: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Pattern: Blank Waves Notes Sharp Wood Rockface Leather Honey Vertical Triangles
Welcome to Xbox Chaos: Modding Evolved

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0
Nobody

C / C++
C: Little To Big Endian

2 posts in this topic

I need to read a binary file in it's proper format, and that includes Big endianess, in which my CPU is intel. Here is what I came up with, but it has an error claiming that bigEndian is violating memory access.


DWORD ReverseInt(DWORD val)
{
int i = 0;
char bigEndian[0x4];
char littleEndian[0x4];
sprintf(littleEndian, "%d", val);
for (i < sizeof(littleEndian); i++; )
{
bigEndian[i] = littleEndian[sizeof(littleEndian) - i];
}
return (DWORD)bigEndian;
}

Share this post


Link to post
Share on other sites

Use compiler intrinsics instead (assuming that your compiler supports them). See the answer to this question: http://stackoverflow.com/questions/105252/how-do-i-convert-between-big-endian-and-little-endian-values-in-c

If your compiler doesn't support those, this function should do the trick:


DWORD byteSwap(DWORD val)
{
return (val << 24) | ((val & 0xFF00) << 8) | ((val >> 8) & 0xFF00) | (val >> 24);
}

WaeV likes this

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0