本文介绍了已签名长到未签名长..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

您能否让我知道如何获得等于有符号长值的无符号长数????我不需要代码,我需要公式.

例如:如果 signed long var = -15 ,那么 var 的无符号值将是什么?

请回复.
请注意,我不是在寻找代码,我只需要公式.

Hi All,

can you please let me know how can I get unsigned long equivalent to signed long value??? i do not want code,i need formula.

Example: if signed long var = -15 then what will be equivalent value of var when it is unsigned?

Please reply.
Please note that i am not looking for code,i need formula only.

推荐答案

nneg = (2**WordSize - n) mod 2**WordSize



用来.对于32位处理器,您的示例值15将为



is used. For a 32-bit processor and your example value 15 that would be

nneg = 2**32 - 15 = 4 294 967 281 = 0xFFFF FFF1



一些较旧的处理器使用One's Complement表示.对他们来说,公式是



Some older processors use One''s Complement representation. For them the formula is

nneg = (2**WordSize-1 - n) mod 2**WordSize



这意味着值0具有两个表示形式,分别为0x00000000和0xffffffff.



which means that the value 0 has two representations namily 0x00000000 and 0xffffffff.




这篇关于已签名长到未签名长..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 00:46