大端和小端的定义与区别
小端字节序中补码转换为原码并用十进制输出
#include <stdio.h>
unsigned char BUFF[4] = { 0XE7,0XFF,0XFF,0XFF };
unsigned char BUFF2[4] = { 0XE7,0XFF,0X00,0X00 };
int Get_OriNum(unsigned char Buff[]) {
int result=0;
if ((Buff[3] & 0X80) == 0) {
result=Buff[3] * 256 * 256 * 256 + Buff[2] * 256 * 256 + Buff[1]*256 + Buff[0];
}
else {
result = Buff[3] * 256 * 256 * 256 + Buff[2] * 256 * 256 + Buff[1] * 256 + Buff[0];
result = -1 * (0xFFFFFFFF - result + 1);
}
return result;
}
int main() {
printf("%d", Get_OriNum(BUFF));
return 0;
}