Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I need to use a 32bit datatype that is in the order of big-endian. I'm unsure of how .NET order's it's data, depending on if it's big/little I could change the data it must hold. Does anyone know what scheme MS uses? The data I'm using is 0x7E.
-Sean
Posted

little endian

when I was working on itunes related stuff, I use the following method to convert the value

private static int Reverse(int value)
{
byte[] data = BitConverter.GetBytes(value);
Array.Reverse(data);
return BitConverter.ToInt32(data, 0);
}

Posted
little endian

when I was working on itunes related stuff, I use the following method to convert the value

private static int Reverse(int value)
{
byte[] data = BitConverter.GetBytes(value);
Array.Reverse(data);
return BitConverter.ToInt32(data, 0);
}

 

 

Nice, thanks again HJB!

-Sean
Posted

Also, you can use BitConverter.IsLittleEndian incase you use something like mono or dotgnu.

 

private static int Reverse(int value)
{
if(!BitConverter.IsLittleEndian)
	return value;
byte[] data = BitConverter.GetBytes(value);
Array.Reverse(data);
return BitConverter.ToInt32(data, 0);
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...