MATLAB: Easy bit reversal

bitsdata typeMATLAB

I need a function to reverse the bits of an int. I see I can flip bytes around, but that doesn't reverse the bit order. Any easy ideas? Thanks.

Best Answer

sum(uint32(bitset(0,1:32,bitget(uint32(X), 32:-1:1))))
(yes, there are other ways, some of them quite short but not necessarily efficient.)