I have a uint16 vector which I need to flip the last 3 bits of every number.
I already have done this but I think there must be an easier solution to do this. Here is my code.
%Turn the vector to binary V_bin = dec2bin(V,16); for i=1:length(V) %Get the last 3 bits tmp = V_bin(14:end); %Convert the string to decimal tmpdec = bin2dec(tmp); %Do the flip tmpflip = bitcmp(uint8(tmpdec)); %Flipped to binary tmpbin = dec2bin(tmpflip); %Replace the flipped bits in the original string V_bin(14:end) = tmpbin(6:end); end V = bin2dec(V_bin);
As you can see there are a lot of lines for a simple operation, I wonder if there is a more efficient method to do the same. Thanks
Play games and win prizes!Learn more