Raphaël Dev
Raphaël Dev

Reputation: 63

C++ : convert uint64_t to unsigned char array

I need to convert for exemple this number : 281474976710655 to a unsigned char array like this one :

unsigned char value[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

I try to memcpy and other techniques but i didn't get the correct value back, always random hex...

I'm not a c++ developer so thanks to explain if you can.

Thanks a lot, bye !

Upvotes: 2

Views: 7753

Answers (1)

Oliv
Oliv

Reputation: 18051

uint64_t x=281474976710655
unsigned char value[sizeof(x)];
std::memcpy(value,&x,sizeof(x));

Upvotes: 10

Related Questions