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