How to change the 7th least significant of a binary code?
Show older comments
I had created a cell array of size <1x368cell>.
Each element of an array contains a binary code such as '11100101'.
I want to change the 7th bit of this code with an external value.
How could I do it?
Please help me.
Accepted Answer
More Answers (2)
Walter Roberson
on 11 Feb 2017
T = cell2mat(YourCell(:));
T(:,7) = new values
NewCell = reshape( mat2cell(T, ones(1, size(T,1)), size(T,2)), 1, []);
2 Comments
Himanshu Nailwal
on 11 Feb 2017
Edited: Walter Roberson
on 12 Feb 2017
Walter Roberson
on 12 Feb 2017
"new values" needs to be '1' not 1. You are not using numeric values for your representation: you are using the characters '0' and '1'
Guillaume
on 11 Feb 2017
There are many ways:
for idx = 1:numel(yourcellarray)
yourcellarray{idx}(7) = '1';
end
cellarrayaschar = char(yourcellarray);
cellarrayaschar(:, 7) = '1';
yourcellarray = cellstr(cellarrayaschar);
yourcellarray = cellfun(@(b) [b(1), '1', b(3:end)], yourcellarray, 'UniformOutput', false);
and more...
Categories
Find more on Data Type Conversion 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!