什么是二进制补码整数? [英] What is a two's complement Integer?

查看:55
本文介绍了什么是二进制补码整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

intshortbyte 等 Java 数据类型是二进制补码整数,因为它们在 此处.当有人说在 java 中,intshortbyte 是二进制补码整数时,它给出了什么信息?

Java Datatypes like int,short,byte are two's complement integers ,as they menioned it in here . what information does it give when someone says that in java , int ,short or byte are two's complement integers ?

更新:我想知道为什么 2 的补码比其他表示更受欢迎?

Update : i wanted to know why 2's complement is prefered over other representations ?

推荐答案

它告诉您有符号值 (+/-) 是如何以二进制形式表示的.

it tells you how signed values (+/-) are represented in binary form.

例如

简单的二进制形式的 24 是 00011000

24 in simple binary form is 00011000

  • 一个的补码是 11100111(反转所有位)
  • 二进制补码是通过将一个补码值加 1 来计算的

--> 11101000 是 -24 的二进制补码

--> 11101000 is the two's complement for -24

这就是为什么(例如)在 java 中字节值的范围是 -128 ... 127所有在 2^7 位置为 '1' 的值都是负数.

that's why (as an example) in java the range of a byte-value is -128 ... 127 all values having a '1' in the 2^7 position are negative.

这篇关于什么是二进制补码整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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