Dean Chen
Dean Chen

Reputation: 3890

how to calculate the one's complement for positive and negative number?

If I use one's complement to represent number, what result should I get?
For example, number 01110 ( a positive number),its one's complement should be 01110 or 10001?
if the number is 10001 ( a negative number), the one's complement value is 01110?

Upvotes: 1

Views: 55089

Answers (3)

Amer Abubakar
Amer Abubakar

Reputation: 31

One's complement, two's complement and signed magnitude are all the same for positive numbers. For negative numbers take the binary for the absolute value (positive number) and reverse it to get the one's complement. Add one to the 1's complement to get 2's complement......And add 1 extra bit to the most left of the original to get Sign magnitude....

Upvotes: 3

user5880633
user5880633

Reputation: 1

That's completely wrong one's complement, two's complement and signed magnitude are all the same for positive numbers. For negative numbers take the binary for the absolute value (positive number) of the negative number and inverse it to get the one's complement which will be different than two's complement and signed magnitude.

Upvotes: 0

Eran Zimmerman Gonen
Eran Zimmerman Gonen

Reputation: 4507

In your case, it would be 10001. Ones' complement means reversing all the bits in the number.

This also implies that it turns a positive number to a negative one, and vice versa. Also note that this gives some strange behavior, for example zero's complement isn't zero, but negative zero: 00000 becomes 11111. This makes arithmetic with 1's complement a bit tricky, and it is one of the reasons that computers today use 2's complement for negation.

Upvotes: 3

Related Questions