how to convert 8 bit binary numbers into one's and two's complement
Let a=11001011
ones_complement=00110100
twos_complement=00110101

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 1일
편집: Azzi Abdelmalek 2014년 3월 1일

2 개 추천

a='11001011';
c1=not(a-'0') % one's complement
d=1;
for k=numel(a):-1:1
r=d & c1(k);
c2(1,k)=xor(d,c1(k)); % c2 is two's complement
d=r;
end
[c1;c2]

댓글 수: 3

akshay rathod
akshay rathod 2017년 7월 13일
how to work this if i have an array for 512*1 with each row of 16 bits. have to do the loop with this matrix.
Md Rezaul Karim
Md Rezaul Karim 2021년 1월 13일
Thank you so much
Azzi Abdelmalek
Naga viswanathreddy Siddam
Naga viswanathreddy Siddam 2021년 3월 11일
편집: Naga viswanathreddy Siddam 2021년 3월 14일
How can I get reverse of the Two's complement,from a mpu 9250 sensor output!!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

MD SAMIM AKTAR
MD SAMIM AKTAR 2020년 4월 20일

1 개 추천

a='11001011';
c1=not(a-'0') % one's complement
d=1;
for k=numel(a):-1:1
r=d & c1(k);
c2(1,k)=xor(d,c1(k)); % c2 is two's complement
d=r;
end
[c1;c2]

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by