2s是补数存储负数的方法吗? [英] Is 2s complement a way to store negative number?

查看:105
本文介绍了2s是补数存储负数的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多文章和SO答案,以了解2s complement.他们对我有很大帮助.但是,我对2s complement几乎没有疑问.

I have read many articles and SO answers to understand 2s complement. They have helped me a lot. However, there are few doubts in my mind about 2s complement.

1)2s complement是存储负数的一种方法,以简化操作或具有其他一些应用程序吗?

1) Is 2s complement a way to store negative numbers in order to make operation easy or have some other applications too?

2)2s complement是在计算机看到负数时自动获取的吗?

2) 2s complement is taken automatically when computer see a negative number?

3)取2s complement是-编译器的工作或由处理器完成还是什么?

3) Taking 2s complement is -- compiler's job or done by processor or what?

4)在编译时,运行时还是在将值辅助变量时采用2s complement?

4) When 2s complement is taken at -- compile time, run time or at the time of assiging a value to a variable?

我读过的文章(建议您更好地理解2s complement):

Articles I read are (should recommend to understand 2s complement better):

什么是"2的补码"?

为什么用二进制补码来表示负数?

http://www.cs.cornell.edu/〜tomf/notes/cps104/twoscomp.html

推荐答案

1)是.

2)计算机无法看到"负数.它可以看到大量的二进制数据.您的应用程序具有智能地说此二进制数据块是存储在2的compl中的整数".但是,世界上几乎每个CPU都支持2的补码算法.

2) The computer can't "see" a negative number. It can see a chunk of binary data. Your application is what possesses the intelligence to say "this chunk of binary data is an integer stored in 2's compl". However, almost every CPU in the world has support for 2's complement arithmetic.

3)编译器看到诸如int32_t x = 0;之类的源代码,然后意识到此变量以二进制补码格式存储.如果随后添加类似x = x - 1的代码,则编译器在生成程序时会选择使用支持2的补码的处理器指令.处理器仅执行程序告诉它的操作.它没有情报.

3) The compiler sees the source code such as int32_t x = 0; and then realizes that this variable is stored in two's complement format. If you then add code like x = x - 1 the compiler chooses to use processor instructions that support 2's complement, when it generates your program. The processor only does what the program tells it to do. It has no intelligence.

4)如上所述,这是一个编译时决策. (不太确定补余"是什么意思...)

4) As described above, it is a compile-time decision. (Not really sure what you mean with "complement taken"...)

这篇关于2s是补数存储负数的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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