1. ## function help needed

hi!
ive stumbled across this function
heres the code
Code:
```int rev(int a){
int i=1;
if((*(char*)&i)) return(a);
return((a>>24)&0xff)|(((a>>16)&0xff)<<8)|(((a>>8)&0xff)<<16)|((a&0xff)<<24);
}```
of special interest is the second return statement.
the variable a is shifted right by certain values.
the result is masked with 1111 1111. so everywhere where a 1 is in the binary notation of the result a one will be set for that statement.
this result (either 1 or 0) is again ORed with a similar statement.

is all that correc?
well and what is that used for?

thanks alot!

2. My guess is that it is meant to reverse the order of the 8-bit bytes in the input int. So rev(0x12345678) is meant to return 0x78563412. This is spoiled by the over complex and presumably incorrect if statement that returns a if a != 0. Thus as is stands, the function just returns whatever you entered into it. Remove this line and everything starts to work more sensibly!

::edit::
beaten to it by Salem... and I missed the whole endian thing... I shall hang my head in shame

i have implemented my own very basic XOR encryption code.
as usual it encrypts the given ascii text with a key specified by the user.
well.. now i want to tell the user what binary value his original had and what the encrypted text has.

i made a very common approach in creating a bitmask to mask all the bits but not the least significant bit.
then shifting the binary value to the right by one each time would bring me the desired result.

very often i see bitmasks being hexadecimal values like 0xff (1111 1111), or octal ones.
but how would i create my bitmask? in binary it should look like that: 0000 0001.
and how would i create in general my own bitmasks being something special like for example 0100 1110?

is it enough to know how the hexadecimal numbering system works?

thanks alot!

4. kewl.
thanks .

5. heres my samplecode
it doesnt seem to work. its giving me zeroes everywhere in the binary number.
Code:
```#include <stdio.h>

int main (void)
{
unsigned int a = 41;
int i = 8;
printf("unsigned int a = 41\n");
printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
printf("now testing from the msb on if bit is set or not.\n");

//how to create a bitmask like 1000 0000
/*
Hex  	F  	E  	D  	C  	B  	A  	9  	8  	7  	6  	5  	4  	3  	2  	1
Binary 	1111 	1110 	1101 	1100 	1011 	1010 	1001 	1000 	0111 	0110 	0101 	0100 	0011 	0010 	0001
Dec 	15 	14 	13 	12 	11 	10 	9 	8 	7 	6 	5 	4 	3 	2 	1
*/

while(i>0){
else	putchar('0');
i--;
a <<= 1;
}
printf("\n\n");

return 0;
}```

6. thanks it worked.
but isnt this only masking the first half?

7. i see.
thank you.