1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-08 18:02:23 +05:30
gists/c-programming/experiments/bool-operations.c

50 lines
1017 B
C

/*
* bool-operations.c
*
* Author: Intel A80486DX2-66
* License: Unlicense
*/
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#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)
int main(void) {
bool boolean = false;
unsigned char integer = (unsigned char) boolean;
puts("Loop:");
for (uint8_t i = 0; i < 3; i++) {
SHOW_BOOL_INT;
boolean++; integer++;
}
puts("\n* 2:");
boolean *= 2; integer *= 2;
SHOW_BOOL_INT;
puts("\n<< 1:");
boolean <<= 1; integer <<= 1;
SHOW_BOOL_INT;
puts("\n/ 2:");
boolean /= 2; integer /= 2;
SHOW_BOOL_INT;
puts("\n^ 0x10:");
boolean ^= 0x10; integer ^= 0x10;
SHOW_BOOL_INT;
puts("\n>> 1:");
boolean >>= 1; integer >>= 1;
SHOW_BOOL_INT;
return EXIT_SUCCESS;
}