How do perform negation on binary values using matlab?

6 views (last 30 days)
for example given input is = 10011011 i need negation of only MSB bit therefore the result should be =00011011 how can this be performed using MATLAB
  3 Comments
yeshwini
yeshwini on 21 Feb 2014
yes sir, one was binary cancatenation and the other is negation of bit here input is binary means bits

Sign in to comment.

Answers (2)

the cyclist
the cyclist on 20 Feb 2014
Here is one way, if the input is a character string:
char(num2str(x'=='0'))'
I feel that there must be a better way, and I am just being dumb.

the cyclist
the cyclist on 20 Feb 2014
char('a'-x);
where x is your input string.
  5 Comments
the cyclist
the cyclist on 21 Feb 2014
'a' is the character string for the letter 'a'. This is a nice trick to "subtract" your string x from the ASCII character 'a', which gives you what you want.
So, if
x = '0110';
y = char('a'-x);
will result in y having the value '1001'.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!