% bitreverse.m

function rev = bitreverse(a,N)

N = min(N,8);
a = uint8(a);
rev = uint8(0);
for l=1:N
   rev = bitset(rev,N+1-l,bitget(a,l));
end
