A GENDA

   What is endian?
   The little endian
   The big endian
   Source code
E NDIAN ??
   Unit of data handled by a processor in a
    particular architecture is called word. A word is
    basically a fixed sized group of bits that are
    handled as a unit by the instruction set and/or
    hardware of the processor.

   The way a word is stored in memory by different
    architecture is called endianness. There are two
    methods two store a word in computer
    memory, little endian and big endian.
L ITTLE E NDIAN
   In little endian based architecture little end (i.e. least
    significant byte) of a word is stored first.
   Example: In a 32bit architecture a 32 bit hex word say
    0xA6D85FBC is stored at base address 0xA2076F20. In
    a little endian based architecture least significant byte
    of word i.e. 0xBC is stored first and then next least
    significant byte and so on..

       Base_address (0xA2076F20)        : Data 0xBC

       Base_address+1(0xA2076F21) : Data 0x5F

       Base_address+2(0xA2076F22) : Data 0xD8

       Base_address+3(0xA2076F23) : Data 0xA6
B IG E NDIAN
   In big endian based architecture big end (i.e. most
    significant byte) of a word is stored first.

   Example: In a 32bit architecture a 32 bit wide hex
    word say 0xA6D85FBC is stored at base address
    0xA2076F20. In a big endian based architecture most
    significant byte of word i.e. 0xA6 is stored first then
    next most significant byte and so on..

       Base_address (0xA2076F20)      : Data 0xA6

       Base_address+1(0xA2076F21) : Data 0xD8

       Base_address+2(0xA2076F22) : Data 0x5F

       Base_address+3(0xA2076F23) : Data 0xBC
S OURCE C ODE
   Intel processors are little endian based while
    Motorola processors are big endian based.

   Source code to determine weather your
    processor is little or big endian is given below:
    int main()
    {
      int iNum = 1;
      if(*(char *)&iNum == 1)
      {
          printf("nLittle-Endiann");
      }
      else
      {
          printf("Big-Endiann");
S OURCE C ODE
     Source code to convert little endian to big
      endian and vice-versa is given below
    int ChangeEndianness(int num)
    {
    char byte0, byte1, byte2, byte3;

    byte0 = (char)(num & 0x000000FF) >> 0 ;
    byte1 = (char)(num & 0x0000FF00) >> 8 ;
    byte2 = (char)(num & 0x00FF0000) >> 16 ;
    byte3 = (char)(num & 0xFF000000) >> 24 ;

    return (int)((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | (byte3
    << 0));
    }
Q UESTIONS ?
  grj017@gmail.com

Lil endian.ppt

  • 2.
    A GENDA  What is endian?  The little endian  The big endian  Source code
  • 3.
    E NDIAN ??  Unit of data handled by a processor in a particular architecture is called word. A word is basically a fixed sized group of bits that are handled as a unit by the instruction set and/or hardware of the processor.  The way a word is stored in memory by different architecture is called endianness. There are two methods two store a word in computer memory, little endian and big endian.
  • 4.
    L ITTLE ENDIAN  In little endian based architecture little end (i.e. least significant byte) of a word is stored first.  Example: In a 32bit architecture a 32 bit hex word say 0xA6D85FBC is stored at base address 0xA2076F20. In a little endian based architecture least significant byte of word i.e. 0xBC is stored first and then next least significant byte and so on..  Base_address (0xA2076F20) : Data 0xBC  Base_address+1(0xA2076F21) : Data 0x5F  Base_address+2(0xA2076F22) : Data 0xD8  Base_address+3(0xA2076F23) : Data 0xA6
  • 5.
    B IG ENDIAN  In big endian based architecture big end (i.e. most significant byte) of a word is stored first.  Example: In a 32bit architecture a 32 bit wide hex word say 0xA6D85FBC is stored at base address 0xA2076F20. In a big endian based architecture most significant byte of word i.e. 0xA6 is stored first then next most significant byte and so on..  Base_address (0xA2076F20) : Data 0xA6  Base_address+1(0xA2076F21) : Data 0xD8  Base_address+2(0xA2076F22) : Data 0x5F  Base_address+3(0xA2076F23) : Data 0xBC
  • 6.
    S OURCE CODE  Intel processors are little endian based while Motorola processors are big endian based.  Source code to determine weather your processor is little or big endian is given below: int main() { int iNum = 1; if(*(char *)&iNum == 1) { printf("nLittle-Endiann"); } else { printf("Big-Endiann");
  • 7.
    S OURCE CODE  Source code to convert little endian to big endian and vice-versa is given below int ChangeEndianness(int num) { char byte0, byte1, byte2, byte3; byte0 = (char)(num & 0x000000FF) >> 0 ; byte1 = (char)(num & 0x0000FF00) >> 8 ; byte2 = (char)(num & 0x00FF0000) >> 16 ; byte3 = (char)(num & 0xFF000000) >> 24 ; return (int)((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | (byte3 << 0)); }
  • 8.
    Q UESTIONS ? grj017@gmail.com