#include <stdio.h> void PrintBit(int integer) { (integer & 128)?putchar('1'):putchar('0'); (integer & 64)?putchar('1'):putchar('0'); (integer & 32)?putchar('1'):putchar('0'); (integer & 16)?putchar('1'):putchar('0'); (integer & 8)?putchar('1'):putchar('0'); (integer & 4)?putchar('1'):putchar('0'); (integer & 2)?putchar('1'):putchar('0'); (integer & 1)?putchar('1'):putchar('0'); } int main(int argc, char **argv) { unsigned uns; argv++; for(; argc > 1; argc--, argv++) { uns = atoi(*argv); printf("%3d: ", uns); PrintBit(uns); putchar('\n'); } return(0); }
This program take numbers as parameters.. convert from char to unsinedsthen print in binary form.. I make this to smooth the study of bitwises operators
it's useful in this form:
./bitc.o 21 11 $((21&11))
OUTPUT:
21: 00010101
11: 00001011
1: 00000001
Nenhum comentário:
Postar um comentário