I'm trying to get my program to work where a certain bit is being flipped. I have this function called flipbit(int *p, int m)
. The user needs to input a digit and a bit number. Let's say the user gives the number 8
(00001000
) and the bit number 2
, so the 2nd bit in 8 should be flipped, which becomes 00001010
. How can I program this?
EDIT: I made a stupid mistake, I want to count starting from 0, so the 2nd bit in 8 flipped is actually 00001100
instead of 00001010
.
#include <stdio.h>
#include <stdlib.h>
void flipbit(int *p, int m) {
int digit;
digit = *p;
int bit;
bit = &m;
int result;
//printf("The numbers are %d %d", digit, bit);
printf("%d", result);
}
int main() {
int number1;
int number2;
printf("Give number and bit: ");
scanf("%d, %d",&number1, &number2);
flipbit(&number1, &number2);
return 0;
}
-Wall -pedantic
to the command line options). Doing so would have alerted you to the incorrect handling of the second argument to your function.