0% found this document useful (0 votes)
26 views1 page

BigEndian Vs LittleEndian

The document discusses big endian and little endian formats by showing the output of a C program on different systems. It demonstrates how an integer is stored in memory in little endian vs big endian format by printing out each byte. The document also compares the two formats and discusses advantages of each.

Uploaded by

Max Verardi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

BigEndian Vs LittleEndian

The document discusses big endian and little endian formats by showing the output of a C program on different systems. It demonstrates how an integer is stored in memory in little endian vs big endian format by printing out each byte. The document also compares the two formats and discusses advantages of each.

Uploaded by

Max Verardi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Shariful 

Shaikot 

// Big Endian Vs. Little Endian

int
main()
{
int var; // Integer values
char *ptr; // Pointer

// Assign 'var' and output it in byte order and as a value


var = 0x12345678;
ptr = (char *) &var;
printf("ptr[0] = %02X \n", ptr[0]); // Prints 78
printf("ptr[1] = %02X \n", ptr[1]); // Prints 56
printf("ptr[2] = %02X \n", ptr[2]); // Prints 34
printf("ptr[3] = %02X \n", ptr[3]); // Prints 12
printf("var = %08X \n", var); // Prints 12345678

The output of this program is in LITTLE ENDIAN format.


31 30 …………….24     23  22 ……………….16  15  14 ………………..8    7 6 …………………..0

         
1  2  3  4  5  6  7  8 
  ptr[3] ptr[2] ptr[0]
ptr[1]
 

   

  4 bit  8 bit 

Comparison of Big Endian and Little Endian Data Presentation 

Big Endian  Little Endian
Solaris on SPARC  Windows on Intel 

ptr[0] = 12 ptr[0] = 78
ptr[1] = 34 ptr[1] = 56
ptr[2] = 56 ptr[2] = 34
ptr[3] = 78
ptr[3] = 12

var = 12345678 var = 12345678

 
Each byte-order system has its advantages. Little-endian machines let you read
the lowest-byte first, without reading the others. You can check whether a
number is odd or even (last bit is 0) very easily, which is cool if you're into that
kind of thing. Big-endian systems store data in memory the same way we
humans think about data (left-to-right), which makes low-level debugging easier

You might also like