How to shift left a char array?

3 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by