Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !

like image 672
Raphaël Dev Avatar asked Jan 24 '26 10:01

Raphaël Dev


1 Answers

uint64_t x=281474976710655
unsigned char value[sizeof(x)];
std::memcpy(value,&x,sizeof(x));
like image 193
Oliv Avatar answered Jan 26 '26 23:01

Oliv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!