How to shift left a char array?

2 vues (au cours des 30 derniers jours)
RAKESH REDDY
RAKESH REDDY le 14 Mar 2018
Modifié(e) : Stephen23 le 14 Mar 2018
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.

Réponses (1)

Guillaume
Guillaume le 14 Mar 2018
Modifié(e) : Guillaume le 14 Mar 2018
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 commentaire
RAKESH REDDY
RAKESH REDDY le 14 Mar 2018
Modifié(e) : Stephen23 le 14 Mar 2018
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by