1
0

18-bits-logic.c 624 B

12345678910111213141516171819202122232425262728
  1. #include <stdio.h>
  2. int main() {
  3. unsigned int a = 5; // 0000 0101
  4. unsigned int b = 3; // 0000 0011
  5. unsigned int result;
  6. result = a & b; // 0000 0001 (位与)
  7. printf("Bitwise AND: %u\n", result);
  8. result = a | b; // 0000 0111 (位或)
  9. printf("Bitwise OR: %u\n", result);
  10. result = a ^ b; // 0000 0110 (位异或)
  11. printf("Bitwise XOR: %u\n", result);
  12. result = ~a; // 1111 1010 (位取反)
  13. printf("Bitwise NOT: %u\n", result);
  14. result = a << 2; // 0001 0100 (左移)
  15. printf("Left Shift: %u\n", result);
  16. result = a >> 1; // 0000 0010 (右移)
  17. printf("Right Shift: %u\n", result);
  18. return 0;
  19. }