Technical Resources at AEGIS

Java Tips

Shift/Bitwise Operators

By: Velmurugan Periasamy


To understand shift/bitwise operators in Java and to perform calculations, we need to understand how the numbers are represented in different bases. For a good explanation, refer to this description. (External site)

Here are some programs that I wrote in order to understand the operators better. These AWT windows are self-explanatory. They display the bit representation of the number. If you inspect the bit pattern of the result after each bitwise/shift operation, it will give you a good understanding of how those operations work.

Download the zip file and extract it. It contains 3 jar files. Run these jar files using -jar option. (java -jar <JAR name file>)

  1. Shift.jar - Explains shift operators
  2. Shift2.jar - Explains shift operators(User interface is cleaner, I like this more)
  3. Bitwise.jar - Explains bitwise operators

Also, I have placed the same panels into applets (read code reuse J )


You can view them here:

  1. Shift Applet
  2. Shift2 Applet
  3. Bitwise Applet