How to shift left a char array?

조회 수: 2 (최근 30일)
RAKESH REDDY
RAKESH REDDY 2018년 3월 14일
편집: Stephen23 2018년 3월 14일
I have 01111111 array. Now I want to left shift this array by 1 bit and it should delete the shifted MSB bit and should generate 0 as LSB . Output should be like 11111110. By using bitsll operator I am getting an extra bit like 011111110. How can I solve this problem. Can anyone please give me the solution ASAP.

답변 (1개)

Guillaume
Guillaume 2018년 3월 14일
편집: Guillaume 2018년 3월 14일
If you're manipulating char arrays (of '0' and '1') and not actual bits of a number then simply:
shiftedchararray = [yourchararray(2:end), '0']
  댓글 수: 1
RAKESH REDDY
RAKESH REDDY 2018년 3월 14일
편집: Stephen23 2018년 3월 14일
Thank you it is working but I want to replace the LSB bit with logical 1 or 0. I have 10/8 array. It is replacing the LSB bit only for the first row. But for the second row onwards it is not wotrking.
01111111
11111110
00000010
00001010
00100110
10000010
11111110
00000010
00001011
00101100
every row should be shifted left and replaced with logic 0 or 1 which is stored in some variable let it be 'kj'. The code I writtn was
ex=bu(i,:) % here bu is char array
z = [ex(2:end), '0']
kj=num2str(out); %out is logical 1 or 0
z(i,8)=kj;
c=z(i,:)
getting c for the first row correctly but from second row onwards it is giving a single bit like 0 or 1.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by