wang
wang

Reputation: 1

mips code that swap the bits of odd and even position

Write a MIPS program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.

the answer must be MIPS code

Upvotes: 0

Views: 439

Answers (1)

nero
nero

Reputation: 1

just XOR the target number with a 1 string of the same length, eg to flip 1010, 1010 XOR 1111 = 0101 docs

Upvotes: 0

Related Questions