简体   繁体   English

字节shifitng int为4个字节后,如何切换回int(C)

[英]After byte shifitng a int to 4 bytes, how can I shift back to int (C)

So I byte shift a integer into 4 bytes of data. 所以我将一个整数字节移位到4个字节的数据中。

img[4] = (imagewidth >> 24) & 0xFF;
img[5] = (imagewidth >> 16) & 0xFF;
img[6] = (imagewidth >> 8) & 0xFF;
img[7] = imagewidth & 0xFF;

img[8] = (imageheight >> 24) & 0xFF;
img[9] = (imageheight >> 16) & 0xFF;
img[10] = (imageheight >> 8) & 0xFF;
img[11] = imageheight & 0xFF;

Now how would I go about shifting it back to an integer. 现在我将如何将其转换回整数。 so img[8] - img[11] back to a single int or img[4] - img[7] back to a single int 所以img[8] - img[11]回到单个intimg[4] - img[7]回到单个int

imagewidth = img[4] << 24 | img[5] << 16 | img[6] << 8 | img[7];
imageheight = img[8] << 24 | img[9] << 16 | img[10] << 8 | img[11];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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