public class Test {
public static void main(String[] args) {
// 1、 Move left ( << )
// 0000 0000 0000 0000 0000 0000 0000 0101 Then move left 2 Behind you , Low complement 0://
// 0000 0000 0000 0000 0000 0000 0001 0100 The conversion 10 Into the system for 20
System.out.println(5 << 3);// 5 multiply 2 Of 3 Power , So the running result is 40 // 2、 Move right ( >> ) High complement sign bit
// 0000 0000 0000 0000 0000 0000 0000 0101 And then move right 2 position , High compensation 0:
// 0000 0000 0000 0000 0000 0000 0000 0001
System.out.println(9 >> 3);// 9 Divide 2 Of 3 Power , The decimal part is rounded off . So the running result is 1
System.out.println(-5 >> 3);// -5 Divide 2 Of 3 Power , Decimal part in 1, So the running result is -1
 // 3、 unsigned right shift ( >>> ) High compensation 0
// for example -5 Converted to binary, it is :0101 Add... In reverse 1 by 1011
// 1111 1111 1111 1111 1111 1111 1111 1011
// We are respectively right 5 Move right 3 position 、 -5 Move right 3 Bit and unsigned shift right 3 position :
System.out.println(5 >> 3);// The result is 0
System.out.println(-5 >> 3);// The result is -1
System.out.println(-5 >>> 3);// The result is 536870911 // 4、 Bit and ( & )
// Bit and : The... Of the first operand n In the second operand n If all of them are 1, So the result is n Position as 1, Otherwise 0
System.out.println(5 & 3);// The result is 1
System.out.println(4 & 1);// The result is 0 // 5、 Bit or ( | )
// The... Of the first operand n In the second operand n position As long as one is 1, So the result is n Position as 1, Otherwise 0
System.out.println(5 | 3);// The result is 7 // 6、 Bit exclusive or ( ^ )
// The... Of the first operand n In the second operand n position contrary , So the result is n Position as 1, Otherwise 0
System.out.println(5 ^ 3);// The result is 6 // 7、 Bit non ( ~ )
// The number of operands n Position as 1, So the result is n Position as 0, conversely .
System.out.println(~5);// The result is -6
}
}
// An operation 
public class ByteOperatorDemo { public static void main(String[] args) {
// Running results
// 1
// [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 ]
// 2147483647
// [0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ]
// -2
// [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 ]
printValueAnd32Byte(1);
printValueAnd32Byte(Integer.MAX_VALUE);
printValueAnd32Byte(Integer.MAX_VALUE<<1);
} static void printValueAnd32Byte(int x){
System.out.println(x);
System.out.print("[");
for (int i = 31; i >= 0; i--) {
System.out.print(((x >>> i) & 1) + " ");
}
System.out.println("]");
}
}

【Java Basics 】3、Java An operation ( displacement 、 Bit and 、 or 、 Exclusive or 、 Not ) More articles about

  1. JAVA Basics 1—— byte &amp; An operation

    Bytes occupied & Value range Java Altogether 8 Basic data types ( Raw data type ): type Storage requirements Range ( contain ) The default value is Packaging int 4 byte (32 position ) -2^31~ 2^31-1 0 Intege ...

  2. java Basics - learn java util Class library summary

    JAVA Basics Util Package introduction learn Java Basic tool class library java.util package . In this bag ,Java Some practical methods and data structures are provided . This chapter is an introduction. Java Utility class library for java.util package . In this bag ,Java ...

  3. Black horse programmer :Java Basic summary ----java annotation

    Black horse programmer :Java Basic summary java annotation   ASP.Net+Android+IO Development . .Net train . Looking forward to communicating with you ! java annotation lang The basic annotations in the package @SuppressWarnings ...

  4. Java Basics :Java Four kinds of quotations from

    stay Java Basics :java virtual machine (JVM) in , We mentioned that Java Four kinds of quotations from . Include : Strong citation , Soft citation , Weak reference , Virtual reference . This blog will explain these four kinds of quotation in detail . 1. Strong citation 2. Soft citation 3. Weak reference 4. virtual ...

  5. java Basics ( Two )-----java The inheritance of the three characteristics of

    stay <Think in java> There is such a sentence in : Reuse code is Java One of the many compelling features . But to be a revolutionary language , It's not enough to just copy the code and change it , It has to be able to do more . In this sentence ...

  6. Java Basics - Use JAVA Code analysis MD5 Algorithm implementation process

    Java Basics - Use JAVA Code analysis MD5 Algorithm implementation process author : Yin Zhengjie Copyright notice : Original works , Declined reprint ! Otherwise, the legal liability will be investigated .

  7. Java An operation ( displacement 、 Bit and 、 or 、 Exclusive or 、 Not )

    Java The bit operators provided are : Move left ( << ). Move right ( >> ) . unsigned right shift ( >>> ) . Bit and ( & ) . Bit or ( | ). Bit non ( ~ ). Bit exclusive or ( ...

  8. 【Java Basics 】Java Basic data types and bit operations

    1. Assignment operator The assignment uses the operator “=”. It means “ Take the value on the right ( That is right value ), Copy it to the left ( That is, left value )”. The right value can be any constant . Variables or expressions ( As long as it can Generate Just one value ). But the left has to be a clear , Named ...

  9. Java Basic things ( Bitwise operations )

    http://aokunsang.iteye.com/blog/615658 Prelude :   Yesterday a friend asked me Java Can you , I said no , Think about the trouble , Generally, there is displacement Java No code , A few people will , ...

Random recommendation

  1. [Unity3D] Clever use of parents and children to achieve Camera Scene plane walkthrough

    This article was originally written by the author , Reprint please indicate the source It took the entry-level writer a whole morning to get to know the point of Euler Camera rotate ..=.= When debugging scenarios , Every time I press it instinctively W Want to move forward , But it's impossible ( ha-ha ) So on a whim, I wanted to add a Ke ...

  2. python Start the server

    3.*             python -m http.server [port] & 2.*             python -m SimpleHTTPServer [port] ...

  3. MySQL Two temporary tables in

    source : Alibaba cloud RDS - Database kernel group link :http://mysql.taobao.org/monthly/2016/06/07/ External temporary table adopt CREATE TEMPORARY TABLE Created ...

  4. Android Call system camera and custom camera

    0. review Custom camera , Here's a simple camera function , The official document also contains the corresponding content about video shooting , Not here 1. Add permissions <!-- Camera permissions , data storage --> <uses-permission and ...

  5. Traverse DataSet

    DataSet ds=new DataSet ; // obtain dataset First of all table, Take other table Just change the subscript DataTable dt=ds.tables[]; // Traversal line foreach( ...

  6. 【 turn 】android MSM8974 On DeviceTree brief introduction ---- Pretty good

    Original website :http://blog.csdn.net/dongwuming/article/details/12784213 brief introduction The main function is not to hard code the device information in the code , It's described in a special document . system-wide ...

  7. All easy personnel attendance salary factory inspection management system software to create a connection SQL2000 Operation method and description of database

    All easy personnel attendance salary factory inspection management system software to create a connection SQL2000 Operation method and description of database . Quanyitong personnel attendance salary factory inspection management system software , Yes 2 Species database , One is ACCESS, The other is SQL. But due to the ACCESS The database is relatively small , ...

  8. [ZJOI2007] Chessboard making

    Title Description Chess is one of the oldest games in the world , And Chinese go . Chess and Japanese Jiangqi share a great reputation . It is said that chess originated from the idea of the book of changes , The chessboard is a 8*8 The size of the black and white square , Corresponding to the eight hundred and sixty-four hexagrams , Black and white correspond to Yin and Yang . And ours ...

  9. C# Event and delegation

    from https://www.cnblogs.com/sjqq/p/6917497.html C# Event and delegation [ The essence of Look more ] Delegatedelegate yes C# A type of , It's actually a ...

  10. (Python Basics ) The cognition of the list

    Here are some knowledge points of the list name = [' Guan yu ',' Zhang Fei ',' Liu bei ',' Cao Cao ',' Zhugeliang ',' Lyu3 bu4 ',[' Lyu3 bu4 ',' Lyu3 bu4 ',],' Lyu3 bu4 ',' Lyu3 bu4 ',' Lyu3 bu4 ',' Lyu3 bu4 ']for i in name: p ...