Ipower web hosting - Chapter 20 Java Utilities Package and Bit Manipulation

Chapter 20 Java Utilities Package and Bit Manipulation 1179 able value is left shifted one bit by the expression value <<= 1 (this is equivalent to value =value <<1). These steps are repeated for each bit in variable value. At the end of method getBits, the StringBufferis converted to a Stringin line 79 and returned from the method. Figure 20.7 summarizes the results of combining two bits with the bitwise AND (&) operator. Common Programming Error 20.1 Using the logical AND operator (&&) for the bitwise AND operator (&) is a common programming error. Figure 20.8 demonstrates the bitwise AND operator, the bitwise inclusive OR operator, the bitwise exclusive OR operator and the bitwise complement operator. The program uses method getBits (lines 163 188) to get a String representation of the integer values. The program allows the user to enter values into JTextFields (for the binary operators, two values must be entered), and then to press the button representing the operation they would like to test. The program displays the result of each operation in both integer and bitwise representations. The first output window for Fig. 20.8 shows the results of combining the value 65535 and the value 1with the bitwise AND operator (&). All the bits except the low-order bit in the value 65535 are masked off (hidden) by ANDing with the value 1. Bit 1 Bit 2 Bit 1 &Bit 2 000 100 010 111 Fig. 20.7Results of combining two bits with the bitwise AND operator (&). 20. 1 // Fig. 20.8: MiscBitOps.java 2 // Using the bitwise AND, bitwise inclusive OR, bitwise 3 // exclusive OR, and bitwise complement operators. 4 5 // Java core packages 6 import java.awt.*; 7 import java.awt.event.*; 8 9 // Java extension packages 10 import javax.swing.*; 11 12 public class MiscBitOps extends JFrame { 13 private JTextField input1Field, input2Field, 14 bits1Field, bits2Field, bits3Field, resultField; Fig. 20.8Demonstrating the bitwise AND, bitwise inclusive OR, bitwise exclusive OR Fig. 20.8 and bitwise complement operators (part 1 of 6).
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Leave a Reply