Clear Filters
Clear Filters

2's complement of a row in a matrix

3 views (last 30 days)
Hi. For a = [m n] matrix, where each element value is 0 or 1. I want to get the 2's complement of rows depending on the first element value of a row. If a(m,1) = 1, then 2's complement will be performed.
How this 2's complement operation can be performed?
Any advice would be appreciated.
  1 Comment
Andrei Bobrov
Andrei Bobrov on 13 Dec 2011
read http://en.wikipedia.org/wiki/Two%27s_complement

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Dec 2011
To construct the twos-complement of a binary vector, do a bit-wise negation of the vector, and then undertake the steps necessary to add 1 to the end of the vector, propagating any carry "left-ward" until there is no carry remaining.
  2 Comments
Jan
Jan on 13 Dec 2011
Thanks, Walter. I've removed my answer.
Ayesa
Ayesa on 14 Dec 2011
Thank you for your suggestion. It helps me to write the code. Again many thanks.

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!