2024-02-24 14:35:20 +05:30
|
|
|
/*
|
|
|
|
* bool-operations.c
|
|
|
|
*
|
|
|
|
* Author: Intel A80486DX2-66
|
2024-04-26 01:46:39 +05:30
|
|
|
* License: Unlicense
|
2024-02-24 14:35:20 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2024-06-26 01:40:50 +05:30
|
|
|
#include <stdlib.h>
|
2024-02-24 14:35:20 +05:30
|
|
|
|
2024-06-26 01:45:35 +05:30
|
|
|
#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 14:35:20 +05:30
|
|
|
|
2024-04-22 02:14:56 +05:30
|
|
|
int main(void) {
|
2024-02-24 14:35:20 +05:30
|
|
|
bool boolean = false;
|
2024-06-26 01:44:34 +05:30
|
|
|
unsigned char integer = (unsigned char) boolean;
|
2024-02-24 14:35:20 +05:30
|
|
|
printf("Loop:\n");
|
|
|
|
for (uint8_t i = 0; i < 3; i++) {
|
2024-06-26 01:44:34 +05:30
|
|
|
SHOW_BOOL_INT;
|
|
|
|
boolean++; integer++;
|
2024-02-24 14:35:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n* 2:\n");
|
2024-06-26 01:44:34 +05:30
|
|
|
boolean *= 2; integer *= 2;
|
|
|
|
SHOW_BOOL_INT;
|
2024-02-24 14:35:20 +05:30
|
|
|
|
|
|
|
printf("\n<< 1:\n");
|
2024-06-26 01:44:34 +05:30
|
|
|
boolean <<= 1; integer <<= 1;
|
|
|
|
SHOW_BOOL_INT;
|
2024-02-24 14:35:20 +05:30
|
|
|
|
|
|
|
printf("\n/ 2:\n");
|
2024-06-26 01:44:34 +05:30
|
|
|
boolean /= 2; integer /= 2;
|
|
|
|
SHOW_BOOL_INT;
|
2024-02-24 14:35:20 +05:30
|
|
|
|
|
|
|
printf("\n^ 0x10:\n");
|
2024-06-26 01:44:34 +05:30
|
|
|
boolean ^= 0x10; integer ^= 0x10;
|
|
|
|
SHOW_BOOL_INT;
|
2024-02-24 14:35:20 +05:30
|
|
|
|
|
|
|
printf("\n>> 1:\n");
|
2024-06-26 01:44:34 +05:30
|
|
|
boolean >>= 1; integer >>= 1;
|
|
|
|
SHOW_BOOL_INT;
|
2024-02-24 14:35:20 +05:30
|
|
|
|
2024-06-26 01:40:50 +05:30
|
|
|
return EXIT_SUCCESS;
|
2024-02-24 14:35:20 +05:30
|
|
|
}
|