I have a question about memcpy that I hope someone can answer. Here is a small demo program:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main (int argc, char **argv){
unsigned char buffer[10];
unsigned short checksum = 0x1234;
int i;
memset(buffer, 0x00, 10);
memcpy(buffer, (const unsigned char*)&checksum, 2);
for(i = 0; i < 10; i ++){
printf("%02x",buffer[i]);
}
printf("\n");
return 0;
}
When I run this program, I get 34120000000000000000.
My question is: why am I not getting 12340000000000000000?
Many thanks
source
share