IT/C and C++

Bit 탐색

KSI 2005. 7. 13. 06:54
#include <stdio.h>
#define BITMAX 8
#define ZEROBIT 0
unsigned char marin_index; unsigned char killmarin_num;
void main() {
printf("Killed Marin Number(255) :"); scanf("%d", &marin_index);   for(unsigned char i=BITMAX; i>ZEROBIT; i--) { if(marin_index & (1 << (BITMAX - i))) killmarin_num += (1 << (BITMAX - i)); }  printf("Killed Marin Number ? %d", killmarin_num);   printf("Killed Marin Number(255) :"); scanf("%d", &marin_index);

}