Question: Take an int as input using console or JOptionPane I/O and use bitwise operations for the following tasks. Output the results at each step in

Take an int as input using console or JOptionPane I/O and use bitwise operations for the following tasks. Output the results at each step in an easily-understandable manner. There is a way to use Scanner methods to take the input in binary or hex, but it is also OK to take it in decimal; just think about this carefully when you check your results. Express the bitmasks in hex, but also write them out in binary in code comments. You may find it easiest to test your code using hard-coded ints, then add the input code and take out the hard coded values.

In following these instructions, recall that values stored in fixed address in memory are often mapped to the state of pins in I/O ports on electronic devices. In a real device, we would often be setting these bits to the new values we calculate, but for this lab just output the results of the bitwise operations.

1. Output 1 if an integer is odd and 0 if the integer is even (use a bitmask and a bitwise operation, not modulo!)

2. Calculate a value in which the least significant (place value = 1) and fifth-least significant (place value equivalent to decimal 16) bits are set (ie, they each have the value 1, not 0), irrespective of whether they were previously on or off, leaving all other bits as they were in the input.

3. Calculate a value in which the second and third least significant bits are set if and only if they were set in the input, and all other bits are off.

4. Calculate a value in which the second and eighth least significant bits are the reverse of their state in the input and all other bits remain as they were in the input.

5. Use a bitwise operation to multiply the input by 8. Then use a bitwise operation to divide the input number by 8 (integer division, remainder ignored). This step will require that the input be between 8 and about 250 million.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!