Shift left and replace the LSB bit?
13 views (last 30 days)
Show older comments
RAKESH REDDY
on 15 Mar 2018
Commented: RAKESH REDDY
on 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 Comments
Accepted Answer
James Tursa
on 15 Mar 2018
Edited: James Tursa
on 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
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!