A = imread('flamingos.jpg');
J = reshape(uint8(bin2dec(I)), size(A));
toc
Elapsed time is 5.740375 seconds.
toc
Elapsed time is 0.003683 seconds.
J = A - mod(A, uint8(16));
toc
Elapsed time is 0.005185 seconds.
J = uint8(floor(double(A)/16)*16);
toc
Elapsed time is 0.020407 seconds.
J = bitshift(bitshift(A, 4), -4);
toc
Elapsed time is 0.003269 seconds.
So bitshifts is fastest of the methods tried, then bitand(), then subtracting the mod, and the classic approach of division and multiplication is slowest of the mathematical transforms. Relative timings of bitshift compared to bitand is inconsistent; some of the measurements showed bitand to be faster than the bitshift approach, but more of the time bitshift was slightly faster.
Note: you might be tempted to try just plain A/16*16 but that will not work. Division in integer data types is defined to round not to truncate, so for example uint8(3)/2 would be 2 (1.5 rounded) not 1 (1.5 truncated)
I would be more likely to use the bitand() approach rather than the double bit-shift: it provides more flexibility with less thought.
Best Answer