how about something like this?
I think my mind works in strange ways sometimes lol. This is to do a 4 bit word to simplify it a bit.
Code:Unsigned int Reverse(unsigned int var1) { unsigned int a,b,c; unsigned int a = 0; // reversed number goes here int bit; bit = 1; //"bit" is the variable used to mask the var1 and find the values of each bit c = 0; while ( bit<=8) { b = var1 & bit; //find the value of bit 3 - XXX? if (b=0) //if the value is 1 or 0 sets the variable "a" to the flipped version { a = 0; // 0000 c = c | a; //this should set a rolling value of c from its initial value of 0000 //dependant on what the "bit" value is } if (b=1) { a= 8; // 1000 c = c | a; } if (b=2) { a=4; //0100 c = c | a; } if (b=4) { a=2; // 0010 c = c | a; } if (b=8) { a=1; //0001 c = c | a; } <<bit; //shift "bit" left to change the mask } reverse = c; return reverse; }