Shift left and replace the LSB bit?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
RAKESH REDDY
le 15 Mar 2018
Commenté : RAKESH REDDY
le 18 Mar 2018
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 working.
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 written 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.
0 commentaires
Réponse acceptée
James Tursa
le 15 Mar 2018
Modifié(e) : James Tursa
le 15 Mar 2018
bu = your char array
result = bu(:,2:end);
result(:,end+1) = new_bit_char;
E.g.,
>> bu = char((rand(5,8)<0.5)+'0') % some random sample data
bu =
10110111
01000111
11101100
01100101
00111111
>> new_bit_char = '1'
new_bit_char =
1
>> result = bu(:,2:end)
result =
0110111
1000111
1101100
1100101
0111111
>> result(:,end+1) = new_bit_char
result =
01101111
10001111
11011001
11001011
01111111
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!