[英]how to convert negative hexadecimal to decimal
hi I want to know how it is possible to convert a hexadecimal negative value (to complement encoding) to decimal, easily without converting hexadecimal to binary and then multiplying each bit in by a power of 2 and sums all the value to get the result, it takes too much time : example of number (32 bits) : 0xFFFFFE58 嗨,我想知道如何将十六进制负值(到补码编码)转换为十进制,很容易,不用将十六进制转换为二进制,然后将每个位乘以2的幂,并将所有值相加得到结果,它需要太多时间:数字(32位)的例子:0xFFFFFE58
so how can I do it? 那怎么办呢?
without using a computer you can calculate it like this: 没有使用计算机,你可以像这样计算:
0xFFFF FE58 = - 0x1A8 = -(1 * 16² + 10 * 16 + 8) = -(256 + 160 + 8) = -424
0xFFFF FE58
is a negative number in 2's complement. 0xFFFF FE58
是2的补码中的负数。 To get the absolute value you have to invert all bits and add 1 in binary. 要获得绝对值,必须反转所有位并在二进制中加1。 You also can subtract this number from the first number out of range (0x1 0000 0000) 你也可以从超出范围的第一个数字中减去这个数字(0x1 0000 0000)
0x100000000
-0x0FFFFFE58
=
0x0000001A8
now we know that your number is -0x1A8
. 现在我们知道你的号码是-0x1A8
。 now you have to add up the digits multiplied with their place value. 现在你必须将数字乘以它们的位置值。 8 * 16^0 + A (which is 10) * 16^1 + 1 * 16^2 = 424. So the decimal value of your number is -424. 8 * 16 ^ 0 + A(10)* 16 ^ 1 + 1 * 16 ^ 2 = 424.因此您的数字的十进制值为-424。
do a calculation on the positive number, then convert to the negative with Two's complement. 对正数进行计算,然后用二进制补码转换为负数。
see explanation here for positive conversion from hexa to decimal: 请参阅此处有关从六进制到十进制的正转换的说明:
http://www.permadi.com/tutorial/numHexToDec/ http://www.permadi.com/tutorial/numHexToDec/
basically: 基本上:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.