f = @(n)bin2dec(fliplr(dec2bin(0:2^n-1)))
f(0)
f(1)
f(2)
f(3)