big-endian

C# Big-endian ulong from 4 bytes

Hi, Im trying to cast a 4 byte array to an ulong in C#. I'm currently using this code: atomSize = BitConverter.ToUInt32(buffer, 0); The byte[4] contians this: 0 0 0 32 However, the bytes are big-endian. Is there a simple way to convert this big-endian ulong to a little-endian ulong? ...

Unpacking big-endian encoded port number

Hey there! I'm trying to convert a big-endian 2 byte string into a numeric port number. I've already got some code, but I have no idea if it's right: from struct import unpack def unpack_port(big_endian-port): return unpack("!H", big_endian-port)[0] The port (using Python repr() ) is \x1a\xe1, and I get 6881 out of that function. ...

Convert big endian to little endian when reading from a binary file

Hi I'm been looking around how to convert big endian to little endians. But I didn't find any good that could solve my problem. It seem to be there's many way you can do this conversion. Anyway this following code works ok in a big endian system. But how should I write a conversion function so it will work on little endian system as well...

How to write a 24 bit message after reading from a 4-byte integer on a big endian machine (C)?

I am constructing a message to send a 24-bit number over the network. For little endian machines, the code is (ptr is the pointer to the message buffer): *ptr++ = (num >> 16) & 0xFF; *ptr++ = (num >> 8) & 0xFF; *ptr++ = (num) & 0xFF; (So if num0, num1, num2 and num3 are the individual bytes making up num, the message would be e...