one's and two's complement

38 Ansichten (letzte 30 Tage)
Raza Ali
Raza Ali am 1 Mär. 2014
how to convert 8 bit binary numbers into one's and two's complement
Let a=11001011
ones_complement=00110100
twos_complement=00110101

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 1 Mär. 2014
Bearbeitet: Azzi Abdelmalek am 1 Mär. 2014
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 Kommentare
Md Rezaul Karim
Md Rezaul Karim am 13 Jan. 2021
Thank you so much
Azzi Abdelmalek
Naga viswanathreddy Siddam
Naga viswanathreddy Siddam am 11 Mär. 2021
Bearbeitet: Naga viswanathreddy Siddam am 14 Mär. 2021
How can I get reverse of the Two's complement,from a mpu 9250 sensor output!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

MD SAMIM AKTAR
MD SAMIM AKTAR am 20 Apr. 2020
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]

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by