Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 representationStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started