You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
837 B
37 lines
837 B
5 days ago
|
#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;
|
||
|
}
|