In 2's complement calculation system, the most significant bit is used to identify if a number is positive or negative. "signed int" in C is for this purpose.
Currently, I haven't go further inside this feature in C yet. But i want to know, how can I identify a binary number is a positive number or negative? I know how to convert decimal number into binary even negative number. But after i got the result, if I act as another person that want to know if this number is positive number or negative, how can i do that? Stop talking about theory! Show you a example:
/* Example... */
Decimal Binary
---------------------------------------------
255 = 1111 1111 (as usual)
-255 = 1111 1111
= 0000 0000 (negate all bits)
+ 1
--------------------
0000 0001 (end result)
/* ...Example */
Since the '0' for most significant bit indicating positive number and '1' indicating negative number, but if I treat the end result shown above as positive number, it's wrong.
Anybody tell me more about these?...
Thanks for your attention.
Currently, I haven't go further inside this feature in C yet. But i want to know, how can I identify a binary number is a positive number or negative? I know how to convert decimal number into binary even negative number. But after i got the result, if I act as another person that want to know if this number is positive number or negative, how can i do that? Stop talking about theory! Show you a example:
/* Example... */
Decimal Binary
---------------------------------------------
255 = 1111 1111 (as usual)
-255 = 1111 1111
= 0000 0000 (negate all bits)
+ 1
--------------------
0000 0001 (end result)
/* ...Example */
Since the '0' for most significant bit indicating positive number and '1' indicating negative number, but if I treat the end result shown above as positive number, it's wrong.
Anybody tell me more about these?...
Thanks for your attention.