1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2025-01-10 17:32:05 +05:30
gists/c-programming/experiments/bool-operations.c

50 lines
1017 B
C
Raw Normal View History

2024-02-24 12:05:20 +03:00
/*
* bool-operations.c
*
* Author: Intel A80486DX2-66
2024-04-25 23:16:39 +03:00
* License: Unlicense
2024-02-24 12:05:20 +03:00
*/
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
2024-02-24 12:05:20 +03:00
#define BOOL_TO_STR_PADDED(x) ((x) ? "true " : "false")
#define SHOW_BOOL_INT printf("boolean = %s (0x%d) | integer = %s (0x%d)\n", \
BOOL_TO_STR_PADDED(boolean), (int) boolean, \
BOOL_TO_STR_PADDED(integer), (int) integer)
2024-02-24 12:05:20 +03:00
int main(void) {
2024-02-24 12:05:20 +03:00
bool boolean = false;
unsigned char integer = (unsigned char) boolean;
puts("Loop:");
2024-02-24 12:05:20 +03:00
for (uint8_t i = 0; i < 3; i++) {
SHOW_BOOL_INT;
boolean++; integer++;
2024-02-24 12:05:20 +03:00
}
puts("\n* 2:");
boolean *= 2; integer *= 2;
SHOW_BOOL_INT;
2024-02-24 12:05:20 +03:00
puts("\n<< 1:");
boolean <<= 1; integer <<= 1;
SHOW_BOOL_INT;
2024-02-24 12:05:20 +03:00
puts("\n/ 2:");
boolean /= 2; integer /= 2;
SHOW_BOOL_INT;
2024-02-24 12:05:20 +03:00
puts("\n^ 0x10:");
boolean ^= 0x10; integer ^= 0x10;
SHOW_BOOL_INT;
2024-02-24 12:05:20 +03:00
puts("\n>> 1:");
boolean >>= 1; integer >>= 1;
SHOW_BOOL_INT;
2024-02-24 12:05:20 +03:00
return EXIT_SUCCESS;
2024-02-24 12:05:20 +03:00
}