Thread: Reversing bits
View Single Post
Old Apr 17th, 2012, 3:25 AM   #4
Troncoso
Hobbyist Programmer
 
Join Date: Oct 2011
Posts: 127
Rep Power: 7 Troncoso is on a distinguished road
Re: Reversing bits

Dude! Thanks a lot. You gave me the idea that got my program working. It's basically what you did, except I put your

 ADD bitVal to itself to shift bits left by 1

In the inner loop

word = 16 bit word
bitVal = 1
for (int i = 16; 16 > 0; 16--) {
	for (int j = 0; j < i; j++) {
		ADD word to itself to shift bits left by 1
               ADD bitVal to itself to shift bits left by 1
	}
	AND word with x8000 to isolate high order bit
        if (word < 0)
                ADD bitVal to counter
}

Still, I wouldn't have thought of that without you. Thanks again!
Troncoso is offline   Reply With Quote