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

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 1 de Mzo. de 2014
Editada: Azzi Abdelmalek el 1 de Mzo. de 2014

2 votos

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 comentarios

akshay rathod
akshay rathod el 13 de Jul. de 2017
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 el 13 de En. de 2021
Thank you so much
Azzi Abdelmalek
Naga viswanathreddy Siddam
Naga viswanathreddy Siddam el 11 de Mzo. de 2021
Editada: Naga viswanathreddy Siddam el 14 de Mzo. de 2021
How can I get reverse of the Two's complement,from a mpu 9250 sensor output!!

Iniciar sesión para comentar.

Más respuestas (1)

MD SAMIM AKTAR
MD SAMIM AKTAR el 20 de Abr. de 2020

1 voto

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]

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by