How to convert binary bits of a vector, say m, after rotating it left by 1 bit, into decimal ?

2 visualizaciones (últimos 30 días)
m = [16, 10]; % 1x2 array
a = fi(m, 0, 8, 0);
b = bin(bitrol(a, 1)); % Left rotate a by 1 bit
b = 00100000 00010100 % output , 1x19 char
c = bin2dec(b) % decimal representation of b
c = 8212 % output, not same as array 'm'
How to get back m ??
Please help!
  1 comentario
Abdul Gaffar
Abdul Gaffar el 11 de En. de 2021
A small improvement:
m = [16, 10]; % 1x2 array
a = fi(m', 0, 8, 0); % m is changed to m' , where ' denotes transpose
b = bin(bitrol(a, 1)); % Left rotate a by 1 bit
% b = 00100000 00010100 % output , 1x19 char
c = bin2dec(b) % decimal representation of b
d = c' % Added
% d = [32, 20] % output in array format
Thanks!

Iniciar sesión para comentar.

Respuesta aceptada

David Hill
David Hill el 11 de En. de 2021
m = [16; 10]; %use column vector
a = fi(m, 0, 8, 0);
b = bin(bitrol(a, 1));
c = bin2dec(b);
  3 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Argument Definitions en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by