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

2 ビュー (過去 30 日間)
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 件のコメント
Abdul Gaffar
Abdul Gaffar 2021 年 1 月 11 日
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!

サインインしてコメントする。

採用された回答

David Hill
David Hill 2021 年 1 月 11 日
m = [16; 10]; %use column vector
a = fi(m, 0, 8, 0);
b = bin(bitrol(a, 1));
c = bin2dec(b);
  3 件のコメント
David Hill
David Hill 2021 年 1 月 11 日
a=fi(m(:),0,8,0);
b = bin(bitrol(a, 1));
c = reshape(bin2dec(b),size(m));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by