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>)
- Shift.jar - Explains shift
operators
- Shift2.jar - Explains shift
operators(User interface is cleaner, I like this more)
- Bitwise.jar - Explains bitwise operators
Also, I have placed the same panels
into applets (read code reuse J )
You can view them here:
- Shift Applet
- Shift2 Applet
- Bitwise Applet
|