How do you reverse a number using bitwise operator?

Answer:

not 100% sure if this is what you are asking for but here it goes.

you have a number 11110000 (binary) and you want 00001111 (binary)?

you want to use the xor operator ^

value = 0xf0; //11110000 binary
printf("before %d\n");
value ^= 0xff; //11111111 binary
printf("after%d\n");


output:
before 240
after 15

240 in binary is 11110000
15 in binary is 00001111

First answer by ID1290093650. Last edit by ID1290093650. Question popularity: 2 [recommend question].