from
KML Toolbox v2.6
by Rafael Oliveira Create KML/KMZ files and view them in Google Earth. Supports 3D models, contours, overlays, and more
bitslice(a,lowbit,highbit)
function b = bitslice(a,lowbit,highbit)
%BITSLICE(A,LOWBIT,HIGHBIT)
numbits = highbit - lowbit + 1;
b = bitshift(a,-lowbit);
b = fix(b);
b = bitand(b,bitcmp(0,numbits));
b = b/max(b(:));