简体   繁体   中英

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 !

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM