1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Oct 2012
Posts
7
Rep Power
0

#### Change tow bits

Hello there, how I can exchange two bits ?
For example:
We have the number 5 (0101) and we need to change two bits (the user need to choose two bits) - lets say that the user chose the second and the third bits, so the output need to be:
0101--->1001 (The output is 9).

Tnx for help :)
2. Third and fourth. Bits 2 and 3.

Take the number and bitwise-xor it with (1<<2 | 1<<3). Or alternatively xor it with 1<<2 then again with 1<<3.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Oct 2012
Posts
7
Rep Power
0
Originally Posted by requinix
Third and fourth. Bits 2 and 3.

Take the number and bitwise-xor it with (1<<2 | 1<<3). Or alternatively xor it with 1<<2 then again with 1<<3.
I've done that and it's still not working..

Code:
```#include <stdio.h>
void main() {
int var = 0x0005;int new_var; int i=3,j=2;
new_var=(1<<i); new_var=(1<<j);
printf("The old number was: %d , and the new number is: %d \n",var,new_var);
getchar(); }```
4. You haven't bitwised-xor'ed the number and the (two) new_var.