#include "stdio.h" #include "math.h" //--------------------------------------------------------------------------- #define prntvalue(x,y) value=0; for(i=0;i < bits;i++) if (gray_scale[i]=='1') value = value + pow(2,i); printf("%8ld: ",value) #define prntbits(x,y) for(i=0;i < bits;i++) printf("%c",gray_scale[i]) //--------------------------------------------------------------------------- int main(int argc, char **argv) { #define MAXBITS 32 char gray_scale[MAXBITS]; int i,j; int bits; long int index; long int value; if (argc==2) { sscanf(argv[1],"%d",&bits); } else { printf("Please enter the number of gray scale bits to generate: "); scanf("%d",&bits); } if ((bits<=0) || (bits>MAXBITS)) { printf("gray code bits must be between 1 and %d\n",MAXBITS); } else { for (i=0;i0); i--) { j = pow(2,i); if (!(index%j)) break; }; if (gray_scale[i]=='0') gray_scale[i]='1'; else gray_scale[i]='0'; printf("%8d: ", index); prntvalue(bits,gray_scale); prntbits(bits,gray_scale); printf("\n"); } } return 0; }