why memcpy inverts the byte order?

Dear all,

I'm trying to use memcpy to get some kind of information copied into a buffer. My problem is that the order of the copied bytes seems to be inverted from the original order. This is a simplified example of my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 #include <stdio.h>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

using namespace std;

/*
 * 
 */
uint8_t *nonce;

long unsigned int address;
uint32_t counter;
uint8_t seclevel;


void set_nonce(uint8_t *nonce,
long unsigned int extended_source_address,
uint32_t counter,uint8_t seclevel)
{
/*  8 bytes                 || 4 bytes       || 1 byte  */
/*  extended_source_address || frame_counter || sec_lvl  */

memcpy(nonce,&extended_source_address,8);
memcpy(nonce+8,&counter,4);
nonce[12] = seclevel;

}




int main(int argc, char** argv) {
    nonce = new uint8_t[13];
   
  address=0xacde480000000001;
  counter=5;
  seclevel=0x02;
 set_nonce(nonce,address,counter,seclevel);
 

 for(int i=0;i<13;i++){
     
 printf("%02x",nonce[i]);
    
 }

    return 0;
}


the result is 010000000048deac0500000002
and the original order is acde480000000000000000502
So any help.

Thanks in advance.
memcpy does not invert anything. It is just x86 achitecture using little-endian byte order.
http://en.wikipedia.org/wiki/Endianness
Topic archived. No new replies allowed.