I need to pad zeros to specific locations in binary numbers. Looping the array form of a binary number such as dec2bin(43)
and adding the zeros and adjusting th
Although not much of a conceptual improvement, the following will do automatic re-indexing and assignment of the old values on a pre-padded matrix:
>> xx
xx =
1 0 1 0 1 1
nPads = length(positions);
nPadsShifts = 1:nPads;
y = ones(1, length(xx) + nPads); % re-indexing on the new array
y(positions + nPadsShifts) = 0; % padding values
y(y==1) = xx; % set original bit values
>> y
y =
1 0 0 1 0 0 1 1 0