mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-12-26 11:30:03 +05:30
50 lines
1.0 KiB
C
50 lines
1.0 KiB
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;
|
|
printf("Loop:\n");
|
|
for (uint8_t i = 0; i < 3; i++) {
|
|
SHOW_BOOL_INT;
|
|
boolean++; integer++;
|
|
}
|
|
|
|
printf("\n* 2:\n");
|
|
boolean *= 2; integer *= 2;
|
|
SHOW_BOOL_INT;
|
|
|
|
printf("\n<< 1:\n");
|
|
boolean <<= 1; integer <<= 1;
|
|
SHOW_BOOL_INT;
|
|
|
|
printf("\n/ 2:\n");
|
|
boolean /= 2; integer /= 2;
|
|
SHOW_BOOL_INT;
|
|
|
|
printf("\n^ 0x10:\n");
|
|
boolean ^= 0x10; integer ^= 0x10;
|
|
SHOW_BOOL_INT;
|
|
|
|
printf("\n>> 1:\n");
|
|
boolean >>= 1; integer >>= 1;
|
|
SHOW_BOOL_INT;
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|