Shift left and replace the LSB bit?

7 visualizaciones (últimos 30 días)
RAKESH REDDY
RAKESH REDDY el 15 de Mzo. de 2018
Comentada: RAKESH REDDY el 18 de Mzo. de 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.

Respuesta aceptada

James Tursa
James Tursa el 15 de Mzo. de 2018
Editada: James Tursa el 15 de Mzo. de 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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by