Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test your code on a machine with big-endian architecture?

Tags:

Both ideone.com and codepad.org have Little-Endian architechtures.

I want to test my code on some machine with Big-Endian architechture (for example - Solaris - which I don't have). Is there some easy way that you know about?

like image 432
Lazer Avatar asked May 15 '10 05:05

Lazer


People also ask

How do I test my endian machine?

We can write a small tool to test Whether a Machine is Big Endian or Little Endian in C/C++. First, we declare a 16-bit integer (short int), which has the value 0x0001, then we gets its pointer and deference it. If the MSB is stored at lower address (e.g. the value that pointer points to), then it is little endian.

How can you tell if the machine you are coding on is big endian or little endian?

If it is little-endian, it would be stored as “01 00 00 00”. The program checks the first byte by dereferencing the cptr pointer. If it equals to 0, it means the processor is big-endian(“00 00 00 01”), If it equals to 1, it means the processor is little-endian (“01 00 00 00”).

How do you read Big Endians?

Big endian machine: An int is 4 bytes, and the first is the largest. I read 4 bytes (W X Y Z) and W is the largest. The number is 0x12345678. Little endian machine: Sure, an int is 4 bytes, but the first is smallest.

Are there any big endian machines?

Big-endian is the canonical form for storage and the wire because back when the Internet was designed most "pro" machines were big-endian: Sparc, old MIPS, old PPC, DEC Alpha, etc. All these are dead or dying now. It's easy enough to deal with BE files and protocols by just swapping bytes.


1 Answers

QEMU supports emulating several big-endian architectures. Note that some architectures support both endiannesses; some (Itanium, ARM) are primarily used as little-endian while others (PowerPC, MIPS) are primarily used as big-endian.

Aurélien Jarno wrote some HOWTOs on installing Debian on an emulated MIPS or SPARC machine which should be a good start.

like image 95
Nicholas Riley Avatar answered Oct 01 '22 21:10

Nicholas Riley