Why is the range of byte values in Java 128 to 127

Source: Internet
Author: User

Concept: Java uses the complement to denote the binary number, the highest bit of the complement is the sign bit, the highest bit is "0" for positive numbers, and the highest bit is "1" to indicate negative numbers.
a positive complement is its own;
negative complement for the absolute value of all of you take the counter plus 1;
For example:
+21, the second binary representation is 00010101, then its complement is also 00010101
-21, according to the concept of the absolute value of 00010101, you take the inverse of 11101010, plus 1 is 11101011, that is, the binary representation of 21 is 11101011

steps:
1, byte is a byte of 8 bits, the highest bit is the sign bit, that is, the maximum value is 01111111, because the positive complement is itself, that is, this positive number is 01111111
decimal representation is 127
2, the maximum positive number is 01111111, then the minimum negative is 10000000 (the largest negative number is 11111111, that is, 1)
3, 10000000 is the minimum negative number of the complement representation, we put the complement calculation step upside down can be. 10000000 minus 1, 01111111, then reverse 10000000.
because the complement of a negative number is reversed by its absolute value, that is, 10000000 is the absolute value of the smallest negative number, and the 10000000 decimal representation is 128, so the minimum negative number is -128
4, it can be concluded that the value range of byte is 128 to +127
5, Description: The calculation method of each type of value range is roughly the same, interested students can try their own calculation

Supplementary (for non-computer professional students to sweep the blind):
There are 3 representations of the fixed-point number in the computer: original code, inverse code, and complement
[Original code] is the binary fixed-point notation, that is, the highest bit is the sign bit, "0" is positive, "1" is negative, the remaining bits represent the size of the value.
[anti-code] notation: The inverse of a positive number is the same as its original code; the inverse of a negative number is a bitwise negation of its original code, except for the sign bit.
The [complement] notation stipulates that the complement of positive numbers is the same as the original code, and the complement of negative numbers is added to the minus 1 of the inverse code.

Why is the range of byte values in Java 128 to 127

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.