Archive for July, 2007

1192 Java Utilities Package and Bit Manipulation Chapter (Cheap web hosting)

Tuesday, July 31st, 2007

1192 Java Utilities Package and Bit Manipulation Chapter 20 33 34 // textfield for user to input a value from 2 to 1023 35 inputField = new JTextField( 10 ); 36 37 inputField.addActionListener( 38 39 new ActionListener() { 40 41 // determine whether value is prime number 42 public void actionPerformed( ActionEvent event ) 43 { 44 int value = Integer.parseInt( inputField.getText() ); 45 46 if ( sieve.get( value ) ) 47 statusLabel.setText( 48 value + ” is a prime number” ); 49 50 else 51 statusLabel.setText( value + 52 ” is not a prime number” ); 53 } 54 } 55 ); 56 57 inputPanel.add( inputField ); 58 container.add( inputPanel, BorderLayout.NORTH ); 59 60 JTextArea primesArea = new JTextArea(); 61 62 container.add( new JScrollPane( primesArea ), 63 BorderLayout.CENTER ); 64 65 // set all bits from 1 to 1023 66 int size = sieve.size(); 67 68 for ( int i = 2; i < size; i++ ) 69 sieve.set( i ); 70 71 // perform Sieve of Eratosthenes 72 int finalBit = ( int ) Math.sqrt( sieve.size() ); 73 74 for ( int i = 2; i < finalBit; i++ ) 75 76 if ( sieve.get( i ) ) 77 78 for ( int j = 2 * i; j < size; j += i ) 79 sieve.clear( j ); 80 81 // display prime numbers from 1 to 1023 82 int counter = 0; 83 Fig. 20.13 Fig. 20.13 Demonstrating the Sieve of Eratosthenes using a BitSet(part 2 of 3).
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Chapter 20 (Hosting web) Java Utilities Package and Bit Manipulation

Tuesday, July 31st, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1191 The expression b.size() returns the size of the BitSet. The expression b.equals( b1 ) compares the two BitSets for equality. The expression b.toString() creates a Stringrepresentation of the BitSetcontents. This is helpful for debugging. Figure 20.13 revisits the Sieve of Eratosthenes for finding prime numbers, which we discussed in Exercise 7.27. This example uses a BitSetrather than an array to implement the algorithm. The program displays all the prime numbers from 2 to 1023 in a JTextAreaand provides a JTextFieldin which the user can type any number from 2 to 1023 to determine whether that number is prime (in which case a message is displayed in a JLabel). 1 // Fig. 20.13: BitSetTest.java 2 // Using a BitSet to demonstrate the Sieve of Eratosthenes. 3 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.util.*; 8 9 // Java extension packages 10 import javax.swing.*; 11 12 public class BitSetTest extends JFrame { 13 private BitSet sieve; 14 private JLabel statusLabel; 15 private JTextField inputField; 16 17 // set up GUI 18 public BitSetTest() 19 { 20 super( “BitSets” ); 21 22 sieve = new BitSet( 1024 ); 23 24 Container container = getContentPane(); 25 26 statusLabel = new JLabel( “” ); 27 container.add( statusLabel, BorderLayout.SOUTH ); 28 29 JPanel inputPanel = new JPanel(); 30 31 inputPanel.add( new JLabel( 32 “Enter a value from 2 to 1023″ ) ); Fig. 20.13 Fig. 20.13 Demonstrating the Sieve of Eratosthenes using a BitSet(part 1 of 3).
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

1190 Java Utilities Package and Bit Manipulation Chapter (Sex offenders web site)

Monday, July 30th, 2007

1190 Java Utilities Package and Bit Manipulation Chapter 20 Bitwise assignment operators &= Bitwise AND assignment operator. |= Bitwise inclusive OR assignment operator. ^= Bitwise exclusive OR assignment operator. <<= Left shift assignment operator. >>= Right shift with sign extension assignment operator. >>>= Right shift with zero extension assignment operator. Fig. 20.12The bitwise assignment operators. 20.12 20.9 BitSetClass Class BitSet makes it easy to create and manipulate bit sets. Bit sets are useful for representing a set of boolean flags. BitSets are dynamically resizable. More bits can be added as needed, and a BitSetobject will grow to accommodate the additional bits. The statement BitSet b = new BitSet(); creates a BitSetthat initially is empty. Also, a program can specify the size of a BitSet with the statement BitSet b = new BitSet( size ); which creates a BitSetwith sizebits. The statement b.set( bitNumber ); sets bit bitNumber on. This makes the underlying value of that bit 1. Note that bit numbers are zero based, like Vectors. The statement b.clear( bitNumber ); sets bit bitNumber off. This makes the underlying value of that bit 0. The statement b.get( bitNumber ); gets the value of bit bitNumber. The result is returned as true if the bit is on, false if the bit is off. The statement b.and( b1 ); performs a bit-by-bit logical AND between BitSets band b1. The result is stored in b. Bitwise logical OR and bitwise logical XOR are performed by the statements b.or( b1 ); b.xor( b2 );
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Chapter 20 Java Utilities Package and Bit Manipulation (Web design seattle)

Monday, July 30th, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1189 Fig. 20.11 Fig. 20.11 Demonstrating the bitwise shift operators (part 5 of 5). The left shift operator (<<) shifts the bits of its left operand to the left by the number of bits specified in its right operand (performed at line 58 in the program). Bits vacated to the right are replaced with 0s; 1s shifted off the left are lost. The first four output windows of Fig. 20.11 demonstrate the left shift operator. Starting with the value 1, the left shift button was pressed twice, resulting in the values 2 and 4, respectively. The fourth output window shows the result of value1being shifted 31 times. Note that the result is a negative value. That is because a 1 in the high-order bit is used to indicate a negative value in an integer. The right shift operator with sign extension (>>) shifts the bits of its left operand to the right by the number of bits specified in its right operand (performed at line 78 in the program). Performing a right shift causes the vacated bits at the left to be replaced by 0s if the number is positive or 1s if the number is negative. Any 1s shifted off the right are lost. The fifth and sixth output windows show the results of right shifting (with sign extension) the value in the fourth output window two times. The right shift operator with zero extension (>>>) shifts the bits of its left operand to the right by the number of bits specified in its right operand (performed at line 98 in the program). Performing a right shift causes the vacated bits at the left to be replaced by 0s. Any 1s shifted off the right are lost. The eighth and ninth output windows show the results of right shifting (with zero extension) the value in the seventh output window two times. Each bitwise operator (except the bitwise complement operator) has a corresponding assignment operator. These bitwise assignment operators are shown in Fig. 20.12.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

1188 Java Utilities Package and Bit (Unable to start debugging on the web server) Manipulation Chapter

Sunday, July 29th, 2007

1188 Java Utilities Package and Bit Manipulation Chapter 20 132 // append space to buffer every 8 bits 133 if( bit % 8 == 0 ) 134 buffer.append( ‘ ‘ ); 135 } 136 137 return buffer.toString(); 138 } 139 140 // execute application 141 public static void main( String args[] ) 142 { 143 BitShift application = new BitShift(); 144 145 application.setDefaultCloseOperation( 146 JFrame.EXIT_ON_CLOSE ); 147 } 148 149 } // end class BitShift Fig. 20.11 Fig. 20.11 Demonstrating the bitwise shift operators (part 4 of 5).
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

Chapter 20 Java Utilities (Cpanel web hosting) Package and Bit Manipulation

Sunday, July 29th, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1187 80 bitsField.setText( getBits( value ) ); 81 } 82 } 83 ); 84 85 container.add( rightSignButton ); 86 87 // button to right shift value one position with zero extension 88 JButton rightZeroButton = new JButton( “>>>” ); 89 90 rightZeroButton.addActionListener( 91 92 new ActionListener() { 93 94 // right shift one position and display new value 95 public void actionPerformed( ActionEvent event ) 96 { 97 int value = Integer.parseInt( valueField.getText() ); 98 value >>>= 1; 99 valueField.setText( Integer.toString( value ) ); 100 101 bitsField.setText( getBits( value ) ); 102 } 103 } 104 ); 105 106 container.add( rightZeroButton ); 107 108 setSize( 400, 120 ); 109 setVisible( true ); 110 } 111 112 // display bit representation of specified int value 113 private String getBits( int value ) 114 { 115 // create int value with 1 in leftmost bit and 0s elsewhere 116 int displayMask = 1 << 31; 117 118 // buffer to build output 119 StringBuffer buffer = new StringBuffer( 35 ); 120 121 // for each bit append 0 or 1 to buffer 122 for ( int bit = 1; bit <= 32; bit++ ) { 123 124 // use displayMask to isolate bit and determine whether 125 // bit has valueof 0 or1 126 buffer.append( 127 ( value & displayMask ) == 0 ? '0' : '1' ); 128 129 // shift value one position to left 130 value <<= 1; 131 Fig. 20.11 Fig. 20.11 Demonstrating the bitwise shift operators (part 3 of 5).
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

1186 Java Utilities Package and Bit Manipulation Chapter (Medical web site)

Saturday, July 28th, 2007

1186 Java Utilities Package and Bit Manipulation Chapter 20 27 container.add( valueField ); 28 29 valueField.addActionListener( 30 31 new ActionListener() { 32 33 // read value and display its bitwise representation 34 public void actionPerformed( ActionEvent event ) 35 { 36 int value = Integer.parseInt( valueField.getText() ); 37 bitsField.setText( getBits( value ) ); 38 } 39 } 40 ); 41 42 // textfield to display bitwise representation of an integer 43 bitsField = new JTextField( 33 ); 44 bitsField.setEditable( false ); 45 container.add( bitsField ); 46 47 // button to shift bits left by one position 48 JButton leftButton = new JButton( “<<" ); 49 50 leftButton.addActionListener( 51 52 new ActionListener() { 53 54 // left shift one position and display new value 55 public void actionPerformed( ActionEvent event ) 56 { 57 int value = Integer.parseInt( valueField.getText() ); 58 value <<= 1; 59 valueField.setText( Integer.toString( value ) ); 60 bitsField.setText( getBits( value ) ); 61 } 62 } 63 ); 64 65 container.add( leftButton ); 66 67 // button to right shift value one position with sign extension 68 JButton rightSignButton = new JButton( ">>” ); 69 70 rightSignButton.addActionListener( 71 72 new ActionListener() { 73 74 // right shift one position and display new value 75 public void actionPerformed( ActionEvent event ) 76 { 77 int value = Integer.parseInt( valueField.getText() ); 78 value >>= 1; 79 valueField.setText( Integer.toString( value ) ); Fig. 20.11 Fig. 20.11 Demonstrating the bitwise shift operators (part 2 of 5).
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Web hosting contract - Chapter 20 Java Utilities Package and Bit Manipulation

Saturday, July 28th, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1185 Bit 1 Bit 2 Bit 1 ^Bit 2 0 0 0 1 0 1 0 1 1 1 1 0 Fig. 20.10Results of combining two bits with the bitwise exclusive OR operator (^). 20.10 The bitwise complement operator (~) sets all 1bits in its operand to 0in the result and sets all 0 bits to 1 in the result otherwise referred to as taking the one’s complement of the value. The fourth output window for Fig. 20.8 shows the results of taking the one s complement of the value 21845. The result is -21846. The program of Fig. 20.11 demonstrates the left shift operator (<<), the right shift operator with sign extension (>>) and the right shift operator with zero extension (>>>). Method getBits(lines 113 138) obtains a Stringcontaining the bit representation of the integer values. The program allows the user to enter an integer into a JTextField and press Enter to display the bit representation of the integer in a second JTextField. The the user can press a button representing a shift operation to perform a 1-bit shift and view the results of the shift in both integer and bitwise representation. 1 // Fig. 20.11: BitShift.java 2 // Using the bitwise shift operators. 3 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; 7 8 // Java extension packages 9 import javax.swing.*; 10 11 public class BitShift extends JFrame { 12 private JTextField bitsField; 13 private JTextField valueField; 14 15 // set up GUI 16 public BitShift() 17 { 18 super( “Shifting bits” ); 19 20 Container container = getContentPane(); 21 container.setLayout( new FlowLayout() ); 22 23 container.add( new JLabel( “Integer to shift ” ) ); 24 25 // textfield for user to input integer 26 valueField = new JTextField( 12 ); Fig. 20.11 Fig. 20.11 Demonstrating the bitwise shift operators (part 1 of 5).
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

1184 Java Utilities Package and Bit Manipulation Chapter (How to cite a web site)

Friday, July 27th, 2007

1184 Java Utilities Package and Bit Manipulation Chapter 20 Fig. 20.8Demonstrating the bitwise AND, bitwise inclusive OR, bitwise exclusive OR Fig. 20.8 and bitwise complement operators (part 6 of 6). The bitwise inclusive OR operator sets specific bits to 1 in an operand. The second output window for Fig. 20.8 shows the results of combining the value 15and the value 241 by using the bitwise OR operator the result is 255. Figure 20.9 summarizes the results of combining two bits with the bitwise inclusive OR operator. Common Programming Error 20.2 Using the logical OR operator (||) for the bitwise OR operator (|) is a common programming error. The bitwise exclusive OR operator (^) sets each bit in the result to 1 if exactly one of the corresponding bits in its two operands is 1. The third output of Fig. 20.8 shows the results of combining the value 139 and the value 199 by using the exclusive OR operator the result is 76. Figure 20.10 summarizes the results of combining two bits with the bitwise exclusive OR operator. Bit 1 Bit 2 Bit 1 |Bit 2 0 0 0 1 0 1 0 1 1 1 1 1 Fig. 20.9Results of combining two bits with the bitwise inclusive OR operator (|). 20.
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Web space - Chapter 20 Java Utilities Package and Bit Manipulation

Friday, July 27th, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1183 170 171 // for each bit append 0 or 1 to buffer 172 for ( int bit = 1; bit <= 32; bit++ ) { 173 174 // use displayMask to isolate bit and determine whether 175 // bit has valueof 0 or1 176 buffer.append( 177 ( value & displayMask ) == 0 ? '0' : '1' ); 178 179 // shift value one position to left 180 value <<= 1; 181 182 // append space to buffer every 8 bits 183 if( bit % 8 == 0 ) 184 buffer.append( ' ' ); 185 } 186 187 return buffer.toString(); 188 } 189 190 // execute application 191 public static void main( String args[] ) 192 { 193 MiscBitOps application = new MiscBitOps(); 194 195 application.setDefaultCloseOperation( 196 JFrame.EXIT_ON_CLOSE ); 197 } 198 199 } // end class MiscBitOps Fig. 20.8Demonstrating the bitwise AND, bitwise inclusive OR, bitwise exclusive OR Fig. 20.8 and bitwise complement operators (part 5 of 6).
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.