Int,byte of Java data type conversion

Source: Internet
Author: User

Look directly at the following operations:
public class Testconvert{public  static void Main (String []args) {byte b1=67;byte b2=89;byte b= (Byte) (B1+B2);// The system is cast to an int type operation. Must be stronger to convert System.out.println (b);}}
Analysis: The storage space of byte type is 1 bytes, the storage space of the range is -128~127;int type is 4 bytes;

BYTE b1= 67=01000011;//sign bit is positive

BYTE b2= 89=01011001;//sign bit is positive

01000011

+ 01011001

----------------------------------

10011100 (exceeding the upper limit of the presentation range.) The sign bit is 1, which indicates negative numbers)

10011100 to 01100011 and add 1->01100100

IE-(64+32+4) =-100

Here is mainly related to decimal to binary conversion, complement, anti-code!

This is a personal idea, assuming that there are errors in the place also please elegance!

Int,byte of Java data type conversion

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.