#define ARRAY_SIZE 8
#include <stdio.h>
int main(int argc, char *argv[])
{
char a;
int mask, i;
int c[ARRAY_SIZE] = {128, 64, 32, 16, 8, 4, 2, 1};
switch(argc) {
case 2:
a = *argv[1];
printf("%02Xh\n", a);
break;
default:
fprintf(stderr, "bits a\n");
exit(0);
}
for(i = 0; i < ARRAY_SIZE; i++) {
mask = c[i];
if( (a & mask) == mask ) {
printf("1");
} else {
printf("0");
}
}
return 0;
}
>>259 #include <stdlib.h>を追加