Hi Team,
I want to know Atmega2560 is little endian or big endian, i searched on internet but not found exactly about ATmega2560, only i found that most of AVR microcontrollers are little endian, with this info i am proceeding my project. But i want concrete info on ATmega2560 about its endianness. Please help me to get this info.
#include <Arduino.h>
#include <limits.h>
#include <stdint.h>
#if CHAR_BIT != 8
#error "unsupported char size"
#endif
enum
{
O32_LITTLE_ENDIAN = 0x03020100ul,
O32_BIG_ENDIAN = 0x00010203ul,
O32_PDP_ENDIAN = 0x01000302ul
};
static const union { unsigned char bytes[4]; uint32_t value; } o32_host_order =
{ { 0, 1, 2, 3 } };
#define O32_HOST_ORDER (o32_host_order.value)
void setup()
{
Serial.begin( 115200 );
if ( O32_HOST_ORDER == O32_LITTLE_ENDIAN )
{
Serial.println( F( "Little Endian" ) );
}
else if ( O32_HOST_ORDER == O32_BIG_ENDIAN )
{
Serial.println( F( "Big Endian" ) );
}
else if ( O32_HOST_ORDER == O32_PDP_ENDIAN )
{
Serial.println( F( "PDP Endian" ) );
}
else
{
Serial.println( F( "Other Endian" ) );
}
}
void loop() {
// put your main code here, to run repeatedly:
}
According to the code above the ATtiny861 is...
Little Endian
I wonder does PDP_ENDIAN derive from DEC PDP11 mini-computers. We had one in work with a HUGE 10MB drive.
More interestingly how can there be three types of endian-ness?
...R
Robin2:
I wonder does PDP_ENDIAN derive from DEC PDP11 mini-computers. We had one in work with a HUGE 10MB drive.More interestingly how can there be three types of endian-ness?
...R
Based on the code above, it appears that the long word has words with wierd endianness
Instead of 3,2,1,0 or 0,1,2,3 it goes 1,0,3,2.
And now you get a 2 TB drive that can sit on your hand and be taken with you!
I imagine you can take a long number and send out the bytes in any order you want, with MSB or LSB first, so 32 combinations? More if you provide MSB/LSB swapping.
Robin2:
I wonder does PDP_ENDIAN derive from DEC PDP11 mini-computers. We had one in work with a HUGE 10MB drive.More interestingly how can there be three types of endian-ness?
...R
Yes. The PDP-11 floating point format swapped the bytes in each of the two 16-bit words, but the words themselves were not swapped:
If you do:
unsigned long a = 0x01020304U;
the value with be bytes 4, 3, 2, 1 if you look at them individually. On a big endian system, the bytes would be 1, 2, 3, 4. On a mixed endian system like the PDP-11 floating point format, the bytes would be 2, 1, 4, 3.
Thanks for reply....
i used that code and i got confirm its little endian.