Easy bit reversal
48 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Walter Roberson
on 22 Feb 2012
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.)
1 Comment
More Answers (2)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!