endianness

Converting Endianess on a bit field structure

Hi I need to convert a bit-field structure from little-endian to big-endia architecture. What is the best way to do that, as there will be issues in byte boundaries, if I simply swap the structure elements. Ex Structure is: struct { unsigned int b1:1; unsigned int b2:8; unsigned int b3:7; unsigned int b4:8;...

Will 20 year old compatibility issues exist 20 years in the future?

There is nothing like the 43rd day of your life spent tracking down issues due to CR/LF, different slash types, or a Big Endian vs. Little Endian bug. These issues are 20 years old and they make me feel as though humans are still cavemen. Are we simply replacing these old issues for new ones? XML has helped but aren't these issues cos...

64 bit ntohl() in C++ ?

The man pages for htonl() seem to suggest that you can only use it for up to 32 bit values. (In reality, ntohl() is defined for unsigned long, which on my platform is 32 bits. I suppose if the unsigned long were 8 bytes, it would work for 64 bit ints). My problem is that I need to convert 64 bit integers (in my case, this is an unsigned...

Converting grouped hex characters into a bitstring in Perl

I have some 256-character strings of hexadecimal characters which represent a sequence of bit flags, and I'm trying to convert them back into a bitstring so I can manipulate them with &, |, vec and the like. The hex strings are written in integer-wide big-endian groups, such that a group of 8 bytes like "76543210" should translate to th...

How do I convert a big-endian struct to a little endian-struct?

I have a binary file that was created on a unix machine. It's just a bunch of records written one after another. The record is defined something like this: struct RECORD { UINT32 foo; UINT32 bar; CHAR fooword[11]; CHAR barword[11]; UNIT16 baz; } I am trying to figure out how I would read and interpret this data on a Windows...

Why does an 8-bit field have endianness?

See the definition of TCP header in /netinet/tcp.h: struct tcphdr { u_int16_t th_sport; /* source port */ u_int16_t th_dport; /* destination port */ tcp_seq th_seq; /* sequence number */ tcp_seq th_ack; /* acknowledgement number */ # if __BYTE_ORDER == __LITTLE_ENDIAN u_int8...

Supporting byte ordering in Linux user space

I'm writing a program on Linux in C to analyze core files produced from an embedded system. The core files might be little endian (ARM) or big endian (MIPS), and the program to analyze them might be running on a little endian host (x86) or big endian (PowerPC). By looking at the headers I know whether the core is LE or BE. I'd rather my...

Why does BinaryReader.ReadUInt32() reverse the bit pattern?

I am trying to read a binary file with the BinaryReader class, and I need to read it in as blocks of UInt32, and then do some bit shifting etc. afterwords. But, for some reason bit order is reversed when I use the ReadUInt32 method. If I for example have a file where the first four bytes looks like this in hex, 0x12345678, they end up ...

What are the benefits of the different endiannesses?

Why did some processor manifacturers decide to use Little endian Big endian Middle endian Any others? ? I've heard that with big endian one can find out faster, if a number is negative or positive, because that bit is the first one. (This doesn't matter on modern CPUs, as individual bit can't be accessed anymore.) ...

Java's Virtual Machine's Endianness

What endianness does Java use in its virtual machine? I remember reading somewhere that it depends on the physical machine it's running on, and then other places I have read that it is always, I believe, big endian. Which is correct? ...

Big endian or Little endian on net?

In what byte order does data transfer occur on net? Is it Little Endian or big endian? How is it converted to the respective byte order once the data reaches the host ? ...

Detecting endianness programmatically in a C++ program

Is there a programmatic way to detect whether or not you are on a big-endian or little-endian architecture? I need to be able to write code that will execute on an Intel or PPC system and use exactly the same code (i.e. no conditional compilation). ...

Java / Ada Big Endian to Linux Little Endian problems.

I am an intern who has inherited a problem with a testing program at the place where I am working. After searching around on a little bit I can across a person with my exact same problem. After asking around a little bit here, i found out that the guy who posted this does actually still work here, and I am getting his help with this too,...

bitwise operators and "Endianness"

Does Endianness matter at all with the bitwise operations. Either logical or shifting? I'm working on homework with regard to bitwise operators and I can not make heads or tails on it and I think I'm getting quite hung up on the endianess. That is, I'm using a little endian machine (like most are) but does this need to be considered or...

BigEndianBitConverter in Silverlight?

I'm trying to use the MiscUtil.Conversion utility in Silverlight. http://www.yoda.arachsys.com/csharp/miscutil/ When I try to compile it, I get an error saying Silverlight's BitConverter class does not have these two methods: DoubleToInt64Bits Int64BitsToDouble Well, I opened up Reflector and found them in mscorlib: public unsafe lon...

Is the endianness of format params guaranteed in RIFF WAV files?

Is the endianness of format params guaranteed in RIFF WAV files? I have heard conflicting answers to this including references to a RIFX file format. ...

To understand a C code about endianness

I am studying big and little-endianness. 1. What is the purpose of | \ in the following code? ... #elif defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) #define htons(A) ((((uint16_t)(A) & 0xff00) >> 8) | \ (((uint16_t)(A) & 0x00ff) << 8)) ... 2. What is the purpose of (A) in the code? ...

Endianness in casting an array of two bytes into a single short

Problem: I cannot understand the number 256 (2^8) in the extract of the IBM article: On the other hand, if it's a big-endian system, the high byte is 1 and the value of x is 256. Assume each element in an array consumes 4 bites, then the processor should read somehow: 1000 0000. If it is a big endian, it is 0001 0000 because en...

Endianness of "IBM PC" byte order?

I looked at the Wikipedia article on endianness and it doesn't mention anything about this type of byte order (which is what photoshop asks me about when opening RAW files). Which is it? ...

Converting a UINT16 value into a UINT8 array[2]

This question is basically the second half to my other Question How can I convert a UINT16 value, into a UINT8 * array without a loop and avoiding endian problems. Basically I want to do something like this: UINT16 value = 0xAAFF; UINT8 array[2] = value; The end result of this is to store value into a UINT8 array while avoiding end...