반응형

// // bit_test.cpp : Defines the entry point for the console application. // #include "stdafx.h" void printbit(char ch); void cast(int value); int main(int argc, char* argv[]) { cast(255); return 0; } void cast(int value) { printf("char\t : \'%c\' \n", (char)value); printf("dec \t : \'%d\' \n", value); printf("hex \t : \'%x\' \n", value); printf("bit \t : "); printbit( (char)value ); printf("\n"); /* 비트연산자 & : AND 두 비트가 1일때만 1 | : OR 두 비트중 하나 이상 1이면 1 ^ : XOR 같으면 0, 다르면 1 ~ : 1은 0 , 0은 1 */ } void printbit(char ch) { int i; for(i=0;i<8;i++) { printf("%d", (ch&0200) ? 1 : 0); if(i==3) printf(" "); ch = ch << 1; } }



반응형

'c' 카테고리의 다른 글

Browsing Performance Counters  (0) 2011.03.10
CreateProcess 예제  (0) 2008.10.13
java IpAddress To dns name  (0) 2008.06.08
'LPSTR'에서 'LPCWSTR'(으)로 변환할 수 없습니다.  (0) 2008.05.11
[msdn] Windows Data Types  (0) 2008.05.09

+ Recent posts