如何知道二进制整数是否代表负数? [英] How to know if a binary integral number represents a negative number?
问题描述
我正在阅读一些C文本.在负值和正值"会话中,作者提到了几种以二进制形式表示负数的方法.
I am reading some C text. In the Negative and Positive Values session, the author mentioned several ways of representing a negative number in binary form.
我完全理解了,并且想知道是否给定二进制数,我们是否可以确定它是否为负?
I understood all of the way and was wondering if with a give binary number, can we determine if it is negative?
例如,-92具有8位二进制形式:10100100
.但是,如果给我们10100100
,我们可以说它是-92,而不是其他非负数吗?
For example, the -92 has the 8-bit binary form: 10100100
. But if we are given 10100100
can we say that is -92, and not other non-negative number?
推荐答案
当然,这取决于表示形式.在广泛使用的二进制补码中,您只需查看最高有效位.
It depends on the representation, of course. In two's complement, which is widely used, you simply look at the most significant bit.
这篇关于如何知道二进制整数是否代表负数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!