1的补码和2的补码 [英] 1's complement and 2's complement

查看:223
本文介绍了1的补码和2的补码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我对1'和2'的补码

表示有一些疑问。一般来说,负数可以使用

表示1'的补码或2'的补码表示。


1'的补码---反向所有位

2'的补码---反转所有位+ 1


即1'的补码2(0000 0010)是-2(1111 1101)

但是当添加一个数字及其补码时,结果必须是

零对吗?

但是在这种情况0000 0010 + 1111 1101 = 1111 1111 == [?? ]

我们不应该得到零结果???


2'的补充2(0000 0010)是-2( 1111 1110)

加我们得到,0000 0010 + 1111 1110 = 0000 0000 == [确定]


此补码表示是否与C'的〜

[1'的补码]运算符?

这种表示依赖于架构还是编译器依赖?


请澄清,


问候,

Sarathy

解决方案

< BLOCKQUOTE>" sarathy" < sp ********* @ gmail.comwrote:

#大家好,

#我对1'和1有一些疑问2'的补充

#表示。通常负数可以使用

#表示1'的补码或2'的补码表示。



#1'补充---反转所有位

#2'的补码---反转所有位+ 1



#ie 1'的补码2(0000 0010)是-2(1111 1101)

#但是当添加一个数字及其补码时,结果必须是一个

#zero right ??

#但在这种情况下0000 0010 + 1111 1101 = 1111 1111 == [?? ]


在补码机器上,~0为0,称为负零。

有些CPU将-0转换为+0,有些不是'吨。 -0 = + 0,但也有时候-0< +0。


#这个补语表示是否与C'〜

#[1'的补码]运算符有关?


在补充CPU的情况下,-x = ~x。当C

首次创建时,这是否显着,你将不得不问Ritchie。


-

SM Ryan < a rel =nofollowhref =http://www.rawbw.com/~wyrmwif/\"target =_ blank> http://www.rawbw.com/~wyrmwif/

所以....这会让Bethany成为黑色?


sarathy写道:


大家好,

我在1'和2'的补码中有一些疑问

表示。一般来说,负数可以使用

表示1'的补码或2'的补码表示。


1'的补码---反向所有位

2'的补码---反转所有位+ 1


即1'的补码2(0000 0010)是-2(1111 1101)

但是当添加一个数字及其补码时,结果必须是

零对吗?

但是在这种情况0000 0010 + 1111 1101 = 1111 1111 == [?? ]

难道我们不能得到零结果???



在纯1'的补码表示法中,你有减零的概念,

这是补充的补充0.


所以你的结果是减零。


文章< 11 ***** *****************@h48g2000cwc.googlegroups .com> ;,

" sarathy" < sp ********* @ gmail.comwrote:


大家好,

我有一些疑惑1'和2'的补充

表示。一般来说,负数可以使用

表示1'的补码或2'的补码表示。


1'的补码---反向所有位

2'的补码---反转所有位+ 1


即1'的补码2(0000 0010)是-2(1111 1101)

但是当添加一个数字及其补码时,结果必须是

零对吗?

但是在这种情况0000 0010 + 1111 1101 = 1111 1111 == [?? ]

难道我们不能得到零结果???



你做到了。在1'的补码中,没有零的唯一表示。

所有0'和所有1'都等于零。


这个补语表示是否与C'〜

[1'的补码]运算符有关?



不是真的


这种表示架构是依赖还是依赖于编译器?



无论你是做1'的补码还是2'的补码数学都取决于

底层硬件。话虽这么说,我几个月都没见过1'的补充机器。到硬件设计为止,这几乎是一个过时的概念



Hi all,
I have a few doubts in the 1''s and 2''s complement
representation. Generally negative numbers can be represented using
either 1''s complement or 2''s complement representation.

1''s complement ---reverse all the bits
2''s complement ---reverse all the bits + 1

i.e 1''s complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should''nt we be getting a zero as result ???

2''s complement of 2 ( 0000 0010 ) is -2 ( 1111 1110 )
Adding we get , 0000 0010 + 1111 1110 = 0000 0000 ==[ OK]

Does this complement representation have anything to do with the C''s ~
[1''s complement] operator ?
Is this representation architecture dependent or compiler dependent ?

Please clarify,

Regards,
Sarathy

解决方案

"sarathy" <sp*********@gmail.comwrote:
# Hi all,
# I have a few doubts in the 1''s and 2''s complement
# representation. Generally negative numbers can be represented using
# either 1''s complement or 2''s complement representation.
#
# 1''s complement ---reverse all the bits
# 2''s complement ---reverse all the bits + 1
#
# i.e 1''s complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
# But when a number and its complement are added the result must be a
# zero right ??
# But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]

On a ones complement machine, ~0 is 0, called a negative zero.
Some CPUs convert -0 to +0, some don''t. -0 = +0, but also
sometimes -0 < +0.

# Does this complement representation have anything to do with the C''s ~
# [1''s complement] operator ?

On ones complement CPUs, -x = ~x. Whether this was signficant when C
was first created, you would have to ask Ritchie.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So....that would make Bethany part black?


sarathy wrote:

Hi all,
I have a few doubts in the 1''s and 2''s complement
representation. Generally negative numbers can be represented using
either 1''s complement or 2''s complement representation.

1''s complement ---reverse all the bits
2''s complement ---reverse all the bits + 1

i.e 1''s complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should''nt we be getting a zero as result ???

In a pure 1''s complement notation, you have the concept of "minus zero",
which is the ones complement of 0.

So your result is "minus zero".


In article <11**********************@h48g2000cwc.googlegroups .com>,
"sarathy" <sp*********@gmail.comwrote:

Hi all,
I have a few doubts in the 1''s and 2''s complement
representation. Generally negative numbers can be represented using
either 1''s complement or 2''s complement representation.

1''s complement ---reverse all the bits
2''s complement ---reverse all the bits + 1

i.e 1''s complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should''nt we be getting a zero as result ???

You did. In 1''s complement, there is no unique representation for zero.
All 0''s and all 1''s are both equal to zero.

Does this complement representation have anything to do with the C''s ~
[1''s complement] operator ?

Not really

Is this representation architecture dependent or compiler dependent ?

Whether you are doing 1''s complement or 2''s complement math depends on the
underlying hardware. That being said, I haven''t seen a 1''s complement
machine in a couple of eons. It''s pretty much an obsolete concept as far
as hardware design goes.


这篇关于1的补码和2的补码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆