Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentar
Abdul Gaffar
Abdul Gaffar am 11 Jan. 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!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by