Fundamentals of software development data types

Source: Internet
Author: User

A byte contains 8 bits, the first bit is the sign bit, 8 bits can be code 27 times, so the range is -2^7 ~ 2^7-1, i.e. 128 to +127;

Various data types:

The byte type is 1 bytes and can represent a range of -2^7 ~ 2^7-1;

The short type is 2 bytes and can represent a range of -2^16 ~ 2^16-1;

The int type is 4 bytes and can represent a range of -2^31 ~ 2^31-1;

A long type is 8 bytes and can represent a range of -2^64 ~ 2^64-1;

The type of Flaot is also 4 bytes, but its range is much larger than int (from Baidu know: bit sign bit + 8-bit exponent (q) + 23-bit base (b), which is interpreted as: b^q, since the exponent Q is a 8-bit signed integer, the range is-128 ~ 127, the 23-bit base (unsigned) maximum is 2 ^ 23, in the case of the exponent, the maximum can be expressed to 2 ^ 23 ^ 127, but due to the computer's computational capacity constraints, and can not deal with such a large number, but its value range will be much larger than the 32-bit integer. because the float type is a power formula, many times it is not possible to express an exact value , For example 0.1, if the use of float in memory will be represented as 0.10000000000000001, if repeated calculations will result in a very large error);

A double type is also 8 bytes;

Shift operation, signed left "<<":

 Public classTest { Public Static voidMain (String args[]) {System. out. println (Ten<<1 ); Equivalent to: 10*2 System. out. println (Ten<<2 ); Equivalent to:10*2^2 System. out. println (Ten<<3 ); Equivalent to:10*2^3 System. out. println (Ten<<4 ); Equivalent to:10*2^4 }}

Output:

20
40
80
160

  

NONO
Source: http://www.cnblogs.com/diligenceday/

Signed right Move ">>":

 Public classTest { Public Static voidMain (String args[]) {intnum = the; System. out. println (num>>1 ); System. out. println (num>>2 ); System. out. println (num>>3 ); System. out. println (num>>4 ); }}
//Output: the + -Ten

>>>: Unsigned Right shift, ignore sign bit, empty space is 0;

Unsigned right shift has an attribute that must be kept in mind, because in binary: negative values are reversed by +1 , and when we do an unsigned right shift to a negative number, the value of the unsigned right shift will be very large:

 Public class Test {    publicstaticvoid  main (String args[]) {        int num =-1;        System. out. println (num>>>1  );}    }
Output: 2147483647

~: bitwise reverse;

&: bitwise AND;

|: bitwise OR;

^: Bitwise XOR;

But what is the use of these things, refer to the following JS code, the original link:

(! (~+[])+{})[--[~+""][+[]]*[~+[]] + ~~!+[]]+({}+[])[[~!+[]]*~+[]]

Will output: "SB"

Or do you like this?

((""[~+[]]++)+"") [(+[])]+ (!+[]+{}) [(~ (~+[]+~+[]) << (-(~+[])))]

Will output: "Ne"

Reference to the conversion between the systems, the binary reference:

10 binary to 2 binary:

  

2 binary to 10 binary:

  

NONO
Source: http://www.cnblogs.com/diligenceday/

Fundamentals of software development data types

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.