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
2014년 2월 20일
편집: the cyclist
2014년 2월 20일
What is the variable type? Is it a character string?
Image Analyst
2014년 2월 20일
Is this any different than your prior post http://www.mathworks.com/matlabcentral/answers/116422-how-to-perform-cancatenation-of-binary-numbers-using-matlab?
yeshwini
2014년 2월 21일
답변 (2개)
the cyclist
2014년 2월 20일
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.
댓글 수: 1
Alejandro Mesa Dame
2021년 7월 26일
god-tier solution. thanks king.
the cyclist
2014년 2월 20일
char('a'-x);
where x is your input string.
댓글 수: 5
David Young
2014년 2월 20일
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
2014년 2월 21일
I realised that it was deliberate - and effective! I put a solution on Cody, no need to change anything.
yeshwini
2014년 2월 21일
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 Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!