Basic data type, java Basic Data Type

Source: Internet
Author: User

Basic data type, java Basic Data Type

Byte tt = (byte) 130 is equal to-126. Byte occupies one byte, 8 bits. The first digit is the symbol bit. 0 indicates a positive number, and 1 indicates a negative number. Therefore, the value range of byte is [-128,127].

The binary value of 130 is 00000000000000000000000010000010, Which is truncated to byte type. Only the last 8 digits are retained, that is, 10000010. the first digit is 1 or negative, the negative number stored by the computer is a supplementary code. The other bits must be reversed and added with 1. After the value is reversed and 1, this value is-1111110. The binary number is converted to an integer of-126.

Byte a = (byte) 0x00000111; hexadecimal 16*16 + 16 + 1 = 256 + 17 = 0000001 00010001. If the last 8 digits are intercepted, a = 17.

Byte c = (byte) 0xFF; hexadecimal system 15*16 + 15 = 255 = 11111111, the first 1 indicates a negative number, and the bucket stores a supplemental code, if the last 7 digits are reversed and 1 is equal to 1, then c =-1. System. out. println (c); input-1.

The octal value must start with 0, and the decimal value cannot start with 0 (except 0 ).

Byte a = 00000111; For octal 64 + 8 + 1, a = 73.

Byte a = (byte) 00001111; octal 8*8*8 + 64 + 8 + 1 = 00000010 01001001, converted to byte, take the last 8 bits, then a = 73. Byte a = 00001111, an error is returned out of the range [-128,127].

 

Byte occupies 8 places. Short occupies 16 bits. value range: [-32768,327 67]

Short s1 = 1; s1 = s1 + 1; an error is returned. Because 1 is of the int type and the calculation result is of the int type, it must be forcibly converted to the short type and written as s1 = (short) (s1 + 1); or s1 + = 1; this method contains implicit forced type conversion. Equivalent to (short) (s1 + 1)

 

The int type occupies 32 bits in memory and 4 bytes. Value Range: [-2147483648,214 7483647].

2 ^ 31 = 2147483648

 

If the long value is out of the int value range, you must add L or l after the number. Indicates that the value is a long integer.

Long n = 2147483650L + 4, then the n value is 2147483654.

Long m = (long) (2147483647 + 4); computing process: 2147483647 storage is: 01111111 11111111 11111111 11111111 plus 00000000 00000000 00000000 equals 00000100 10000000 00000000 00000000.

The first 1 indicates a negative number. The negative number stores the complement code, and the other bits are reversed with 1. The source code is 11111111 11111111 11111111 11111101. Then m is equal to-(2 ^ 32-1-2) =-2147483645.

 

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.