当前位置:网站首页>Why is the integer type 128 to byte -128
Why is the integer type 128 to byte -128
2022-07-25 22:07:00 【l'amour Хэ рутилин】
public static void main(String[] args) {
short a = 128;
byte b = (byte) a;
System.out.println(b);
}I believe many people know that the result of the above code is -128 , But this is why
Everybody knows short The length of is 16 individual bit position So in int in 128 The binary representation of 0000 0000 1000 0000
java During forced rotation If the long bit is converted to the short bit, the binary value at the end of the long bit that is the same as the short bit is retained , therefore b The binary representation of 1000 0000 but 1000 0000 Convert to decimal to 128, Why is it byte It will be expressed as -128 Well ?
Students who have studied computer know that digital binary in computer The highest bit is the sign bit ,1 Represents a negative value ,0 Represents a positive value . And with complement ( The complement of a positive number is the same as the original code , The complement of negative numbers is based on the original code, and then you add 1.) Is stored in the form of . but 1000 0000 The original code of is still 1000 0000.
Let's understand from two perspectives -128 Why is the complement of 1000 0000.
Understand from the meaning of complement
because :256-128=256+(-128) Complement --( There is only addition in the machine ). Subtraction becomes the addition of complement .
and 256-128=128
therefore 256+(-128) Complement =128
therefore (-128) Complement =256-128
(-128) Complement =128 (1000 0000)
0000 0000 0000 0000 0
1000 0001 1111 1111 -1
1000 0010 1111 1110 -2
1000 0011 1111 1101 -3
... .. Complement constantly -1...
1111 1111 1000 0001 -127
Unable to express 1000 0000 -128
So the rules are 8 In bit binary 1000 0000 Representation bit -128 So when other integers 128 Turn into byte When is -128
边栏推荐
- JS timer and swiper plug-in
- [test development methodology] experience of test development platform PK - choice
- YUV420 yuv420sp image format "recommended collection"
- Uninstall NPM and install NPM_ Use 'NPM uninstall' to uninstall the NPM package 'recommended collection'
- Jenkins+svn configuration
- TFrecord写入与读取
- [dinner talk] those things that seem to be for the sake of the company but are actually incomprehensible (2: soft quality "eye edge" during interview)
- EL表达式改进JSP
- Having met a tester with three years' experience in Tencent, I saw the real test ceiling
- How to solve the problem of using the download Plug-in for export?
猜你喜欢

Three ways to allocate disk space

The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?

Wet- a good choice for people with English difficulties - console translation

What have I experienced to become a harder tester than development?

6-18 vulnerability exploitation - backdoor connection

ansible+Crontab批部署巡检

动画曲线天天用,你能自己整一个吗?看完这篇你就会了!
![[hand tear STL] BitSet (bitmap), bloom filter](/img/bc/a6e3c2ccce478460a2742852eee9cf.png)
[hand tear STL] BitSet (bitmap), bloom filter

jenkins+SVN配置

JMeter websocket接口测试
随机推荐
开户就可以购买收益在百分之六以上的理财产品了吗
MySQL --- 子查询 - 列子查询(多行子查询)
What is partition and barrel division?
Redis foundation 2 (notes)
EL表达式改进JSP
ansible+Crontab批部署巡检
6-18 vulnerability exploitation - backdoor connection
Jmeter--- set proxy recording request
The automation testing post spent 20K recruiting, but in the end, there was no suitable one. Both fresh students are better than them
zigbee开发板(nxpzigbee开发)
C语言:随机生成数+选择排序
JS timer and swiper plug-in
Don't know mock test yet? An article to familiarize you with mock
Flex layout
动画曲线天天用,你能自己整一个吗?看完这篇你就会了!
还不懂mock测试?一篇文章带你熟悉mock
The testing work is not valued. Have you changed your position?
3. Editors (vim)
文件无法保存(文件夹已损坏无法读取怎么办)
dovecot 设置邮箱quota