From ede38f800e474c0ca83a7eb1d77b78bae103d41d Mon Sep 17 00:00:00 2001 From: Peace Date: Fri, 25 Apr 2025 11:30:12 +0900 Subject: [PATCH] bit calculation --- practice/g_bitCalc.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 practice/g_bitCalc.c diff --git a/practice/g_bitCalc.c b/practice/g_bitCalc.c new file mode 100644 index 0000000..a765b4d --- /dev/null +++ b/practice/g_bitCalc.c @@ -0,0 +1,37 @@ +#include + +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; +} \ No newline at end of file