mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-12-27 14:50:23 +05:30
C: add bool-operations.c
This commit is contained in:
parent
bfd51c23c2
commit
a73f75c489
47
c-programming/experiments/bool-operations.c
Normal file
47
c-programming/experiments/bool-operations.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* bool-operations.c
|
||||||
|
*
|
||||||
|
* Author: Intel A80486DX2-66
|
||||||
|
* License: Creative Commons Zero 1.0 Universal
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user