How do perform negation on binary values using matlab?

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 件のコメント

the cyclist
the cyclist 2014 年 2 月 20 日
編集済み: the cyclist 2014 年 2 月 20 日
What is the variable type? Is it a character string?
yeshwini
yeshwini 2014 年 2 月 21 日
yes sir, one was binary cancatenation and the other is negation of bit here input is binary means bits

サインインしてコメントする。

回答 (2 件)

the cyclist
the cyclist 2014 年 2 月 20 日

1 投票

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 2014 年 2 月 20 日

0 投票

char('a'-x);
where x is your input string.

5 件のコメント

David Young
David Young 2014 年 2 月 20 日
Answers - Cody synergy!
the cyclist
the cyclist 2014 年 2 月 21 日
The synergy was quite deliberate on my part. If you would like to enter this as a solution yourself, I will happily delete this one, to give you the credit.
David Young
David Young 2014 年 2 月 21 日
I realised that it was deliberate - and effective! I put a solution on Cody, no need to change anything.
yeshwini
yeshwini 2014 年 2 月 21 日
char('a'-x); helo sir,what is 'a' here
the cyclist
the cyclist 2014 年 2 月 21 日
'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'.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

2014 年 2 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by