Question: CODE IN JAVA 1. (4 points) Write a Java program to swap all bits in odd positions with bits in even positions. The following is

CODE IN JAVA CODE IN JAVA 1. (4 points) Write a Java program to swapall bits in odd positions with bits in even positions. The following

1. (4 points) Write a Java program to swap all bits in odd positions with bits in even positions. The following is a sample output: User enters 682, which is 10 1010 1010 in binary and the output is 01 0101 0101. Enter a Number: 682 User Entered: 1010101010 Bits Swapped: 341 (0101010101) Note: Leading zeros may not be displayed when treating results as integers. For example, treating 01 0101 0101 as an integer, will not produce a leading zero, i.e. the output will be 101010101 which is acceptable. Rule for this Laboratory Assumptions Integers are represented in two's-complement form. Right shifts of signed data are performed arithmetically. Forbidden Conditionals (if or ?:), loops, switch statements, function calls, and macro invocations. Divisions, modulus, and multiplication Relative comparison operators (,=). Allowed operations All bit-level and logic operations. Left and right shifts, but only with shift amounts between 0 and w 1, Addition and subtraction Equality (==) and inequality (! =) tests. Integer constants INT_MIN and INT_MAX Casting between data types int and unsigned, either explicity or implicitly. Standard input & output. You can use any method to convert integer to binary representation

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!