I am working on a project where I need to reverse bits for a number.
For example, if I have 110111100000000 I need to reverse it to 0000000001111011.
I am straight clueless on how to do this. Any help will be greatly appreciated!!
Okay, Stewbond. First off, your method doesn't reverse anything, it only moves them over and then sets the smallest significant to true. He will need a mask.
Secondly, I'm not in the habit of answering homework questions outright, so I gave him some examples of how to do it, but obviously not specific to his homework problem. If he can't figure it out based on what's already there, then he's got to look a little closer into how he's handling his code.
So it seems I should've traced through more carefully. ;)
Actually, it looks like I should've just paid more attention when I came back to this. The OP requires the bits are reversed, and Stewbond's code does that, but for some reason when I looked at your link I was thinking the bits should be "flipped" which is obviously not the case.