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 CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by