I've already created the macros for the assignment, but cannot find the syntax error I get when running the program. Any ideas would be greatly appreciated, thanks.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ODD(X) ((X) & 01)
#define BITON(X,N) (((X) >> N) & 01)
#define ALLON(X,S,E) (((X) & ((((int) pow(2,(E-S))-1) << (E-S))) ^ (((int) pow(2,E-S)-1) << (E-S)))
//-----------------------------------------------------------------------------
int main(void) {
unsigned int U1,BitNumber,Start,End;
printf("Enter an integer : ");
scanf("%ud",&U1);
printf("%u is %s\n",U1,ODD(U1)?"odd":"even");
printf("Enter an integer and a bit number : ");
scanf("%u %d",&U1,&BitNumber);
printf("%u has bit %d %s\n",U1,BitNumber,BITON(U1,BitNumber)?"on":"off");
printf("Enter an integer, start and end bit numbers : ");
scanf("%u %u %u",&U1,&Start,&End);
printf("%u has %s those bits on\n",U1,ALLON(U1,Start,End)?"all":"not all");
return(EXIT_SUCCESS);
}
//-----------------------------------------------------------------------------
Error:
BitOps.c: In function ‘main’:
BitOps.c:23:77: error: expected ‘)’ before ‘;’ token
printf("%u has %s those bits on\n",U1,ALLON(U1,Start,End)?"all":"not all");
^
BitOps.c:26:1: error: expected ‘;’ before ‘}’ token
}
#define BITON(X,N) (((X) >> N) & 01)Wouldn't((X) & (1 << (N)))be better?