Big-Endian on Little-Endian

By Susam Pal on 20 Jun 2010

In this post, I will share how I set up big-endian emulation on my little-endian Intel machine to tets a program for byte order related issues. I used the QEMU PowerPC emulator to set up the big-endian emulation. The steps to do so are documented in the list below.

  1. Install QEMU.

    apt-get update && apt-get install qemu
  2. Download mol- from and copy the file named video.x from the downloaded tarball to /usr/share/qemu/. This is necessary to prevent qemu-system-ppc from complaining about it.

    tar -xjf mol-
    sudo cp mol- /usr/share/qemu/
  3. Create a QEMU hard disk image.

    qemu-img create powerpc.img 2G
  4. Download Debian for PowerPC and install it on the QEMU hard disk image.

    qemu-system-ppc -m 512 -boot d -hda powerpc.img -cdrom debian-504-powerpc-CD-1.iso
  5. Boot the QEMU PowerPC emulator with the new hard disk image.

    qemu-system-ppc -m 512 -hda powerpc.img
  6. Write a small program inside the new Debian system, say, endian.c like this:

    #include <stdio.h>
    int main()
        int n = 1;
        printf(*((char *) &n) ? "little-endian\n" : "big-endian\n");
        return 0;
  7. Compile and execute the C program.

    $ gcc endian.c && ./a.out
Comments | #c | #programming | #technology