Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on What is CPU endianness?
Post
What is CPU endianness?
+10
−0
I was fooling around with the following C code on my trusty old x86 PC:
#include <stdint.h>
#include <stdio.h>
int main (void)
{
uint32_t u32 = 0xAABBCCDD;
uint8_t* ptr = (uint8_t*)&u32;
for(size_t i=0; i<sizeof(uint32_t); i++)
{
printf("%.2X", ptr[i]);
}
}
To my surprise, this prints DDCCBBAA
with all bytes backwards. Someone told me this was because of "endianness" and that my x86 is "little endian". What is the meaning of this?
1 comment thread