gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Quick Q.

#42930 - strager - Mon May 16, 2005 10:23 pm

How to you convert a sign of a number via adding? Do I just add 0x7F..?

Thanks.

#42933 - poslundc - Tue May 17, 2005 12:03 am

Numbers are represented by two's complement.

In this scheme, you can obtain the opposing-sign value of a number by inverting the bits and adding one, eg. xNeg = ~x + 1.

Or you can just multiply it by -1 or use the unary-minus operator (-x), which does the same thing and is infinitely more readable.

Dan.

#42936 - sajiimori - Tue May 17, 2005 12:28 am

Your name sounds like you have a cold.