How do I flip the most significant bit in MIPS?

1

I am trying to convert a number in 2's complement in MIPS to sign magnitude. To do this, I think I would:

  1. subtract 1
  2. 'Not' the word
  3. Flip the most significant bit

For example, 11111111111111111111111111111001 (0xfffffff9) would become 00000000000000000000000000000111 (0x00000007).

I figured out how to do step 1 & 2, but can't figure out step 3. Does anyone know how I would do this?

Also, is there a better way to convert from 2's complement to sign magnitude format in MIPS?

mips

1 Answer

3

If you XOR the value with 0x80000000, the most significant bit will flip. You can do the last two steps (retaining the most significant bit and flipping the others) by XOR'ing with 0x7fffffff.

answered on Stack Overflow Mar 31, 2015 by Aasmund Eldhuset

User contributions licensed under CC BY-SA 3.0