parent
7d7ac8ec82
commit
ede38f800e
@ -0,0 +1,37 @@ |
|||||||
|
#include <stdio.h> |
||||||
|
|
||||||
|
int main() |
||||||
|
{ |
||||||
|
|
||||||
|
int a = 6; // 0110
|
||||||
|
int b = 3; // 0011
|
||||||
|
int result; |
||||||
|
|
||||||
|
printf("result size: %d\n", sizeof(int)); |
||||||
|
|
||||||
|
// AND(&)
|
||||||
|
result = a & b; // 0010 => 2
|
||||||
|
printf("[AND] %d : %x\n", result, result); |
||||||
|
|
||||||
|
// OR(|)
|
||||||
|
result = a | b; // 0111 => 7
|
||||||
|
printf("[OR] %d : %x\n", result, result); |
||||||
|
|
||||||
|
// XOR(^): 두 비트가 다르면 1 반환
|
||||||
|
result = a ^ b; // 0101 => 5
|
||||||
|
printf("[XOR] %d : %x\n", result, result); |
||||||
|
|
||||||
|
// NOT(~): 비트 반전
|
||||||
|
result = ~a; // 1111 1001 => -7
|
||||||
|
printf("[NOT] %d : %x\n", result, result); |
||||||
|
|
||||||
|
// Left Shift(<<): 비트 시프트
|
||||||
|
result = a << 1; // 1100 => 12
|
||||||
|
printf("[<<] %d : %x\n", result, result); |
||||||
|
|
||||||
|
// Right Shift(<<): 비트 시프트
|
||||||
|
result = a >> 1; // 0011 => 3
|
||||||
|
printf("[>>] %d : %x\n", result, result); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
Loading…
Reference in new issue