In Java, the type of int is strongly converted to byte, and after a strong conversion to byte, the data exceeds the expression range of byte.

Source: Internet
Author: User

public class Aa {

public static void Main (string[] args) {byte i = 88;  byte R = 68;    byte F = (byte) (i + R); System.out.println (f);

}

}

Output is-100

88+68=156; binary is represented as: 1001 1100, after casting to byte, because Byte is signed, the value range is: -128-127;1001 1100 is a byte number of the complement, we convert it to the original code, that is, minus one after the reverse, but the sign bit can not change, Get: 1110 0100, this number is--100.

Summary: (88+68) -127+ (-128)-1

In Java, the type of int is strongly converted to byte, and after a strong conversion to byte, the data exceeds the expression range of byte.

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.