简体   繁体   English

从字节表示的 Int 计算

[英]Int calculation from byte representation

Given bytes as HEX: 710e00fe I do the following:给定字节为 HEX: 710e00fe我执行以下操作:

int value = (*(int*)([bytes bytes]));
int exp = value >> 24; 
int mantissa = value & 0x00FFFFFF;

And I get mantissa = 3697 and exponent = -2 .我得到mantissa = 3697 and exponent = -2

I tried doing this manually but I can't figure out how I got those values.我尝试手动执行此操作,但我无法弄清楚我是如何获得这些值的。 I can actually get the exp right, but mantissa is a huge number when I manually calculate.我实际上可以得到正确的 exp,但是当我手动计算时,尾数是一个巨大的数字。 Is there something wrong?有什么不对?

You have a little-endian CPU.你有一个小端 CPU。
So, the exponent is the last byte in bytes, ie 0xfe == -2 in two's complement.因此,指数是字节中的最后一个字节,即二进制补码中的 0xfe == -2。

And the mantissa is 0x000e71, ie 3697.尾数为0x000e71,即3697。

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

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