Answered step by step
Verified Expert Solution
Link Copied!

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 image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

7. How will you encourage her to report back on the findings?

Answered: 1 week ago

Question

Were the decisions based on appropriate facts?

Answered: 1 week ago

Question

Were the right people involved in the decision-making process?

Answered: 1 week ago