1
我有一大堆字節稱爲內存,我試圖將這些字節中的8個轉換爲uint64_t。我試圖用big-endian打印這個號碼。將字節數組轉換爲uint64_t?
我有這個至今:
uint64_t value = (uint64_t)(memory[256]) | //location contains byte 88
(uint64_t)(memory[257]) << 8 | //77
(uint64_t)(memory[258]) << 16 | //66
(uint64_t)(memory[259]) << 24 | //55
(uint64_t)(memory[260]) << 32 | //44
(uint64_t)(memory[261]) << 40 | //33
(uint64_t)(memory[262]) << 48 | //22
(uint64_t)(memory[263]) << 56; //11
我打印像這樣:
printf("0x%x", value);
輸出是0x55667788
,但我想輸出爲0x1122334455667788
。
有關如何修復上述代碼以打印0x1122334455667788
的任何建議?
解決方法:需要print語句:
printf("0x%lx", value);
編譯器是否會警告你某件事? –
我不知道這個..但我在這裏發現了一個類似的問題... http://stackoverflow.com/questions/4142251/convert-array-of-8-bytes-to-signed-long-in-c –
我沒有得到一個,不。 –