From a73f75c489e0a3fd8b15441d8b03b7c767dc625d Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Sat, 24 Feb 2024 12:05:20 +0300 Subject: [PATCH] C: add bool-operations.c --- c-programming/experiments/bool-operations.c | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 c-programming/experiments/bool-operations.c diff --git a/c-programming/experiments/bool-operations.c b/c-programming/experiments/bool-operations.c new file mode 100644 index 0000000..0922ab1 --- /dev/null +++ b/c-programming/experiments/bool-operations.c @@ -0,0 +1,47 @@ +/* + * bool-operations.c + * + * Author: Intel A80486DX2-66 + * License: Creative Commons Zero 1.0 Universal + */ + +#include +#include +#include +#include + +#define BOOL_TO_STR(x) ((x) ? "true" : "false") +#define SHOW_BOOL printf("boolean = %s\t(0x%" PRIxMAX ")\n", \ + BOOL_TO_STR(boolean), \ + (uintmax_t) boolean) + +int main() { + bool boolean = false; + printf("Loop:\n"); + for (uint8_t i = 0; i < 3; i++) { + SHOW_BOOL; + boolean++; + } + + printf("\n* 2:\n"); + boolean *= 2; + SHOW_BOOL; + + printf("\n<< 1:\n"); + boolean <<= 1; + SHOW_BOOL; + + printf("\n/ 2:\n"); + boolean /= 2; + SHOW_BOOL; + + printf("\n^ 0x10:\n"); + boolean ^= 0x10; + SHOW_BOOL; + + printf("\n>> 1:\n"); + boolean >>= 1; + SHOW_BOOL; + + return 0; +}