mirror of
https://gitlab.com/80486DX2-66/gists
synced 2025-03-10 16:19:10 +05:30
bool-operations.c: compare to unsigned char
This commit is contained in:
parent
105deedfac
commit
cbaf939777
@ -12,37 +12,38 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define BOOL_TO_STR(x) ((x) ? "true" : "false")
|
#define BOOL_TO_STR(x) ((x) ? "true" : "false")
|
||||||
#define SHOW_BOOL printf("boolean = %s\t(0x%" PRIxMAX ")\n", \
|
#define SHOW_BOOL_INT printf("boolean = %s\t(0x%d) | integer = %s\t(0x%d)\n", \
|
||||||
BOOL_TO_STR(boolean), \
|
BOOL_TO_STR(boolean), (int) boolean, \
|
||||||
(uintmax_t) boolean)
|
BOOL_TO_STR(integer), (int) integer)
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
bool boolean = false;
|
bool boolean = false;
|
||||||
|
unsigned char integer = (unsigned char) boolean;
|
||||||
printf("Loop:\n");
|
printf("Loop:\n");
|
||||||
for (uint8_t i = 0; i < 3; i++) {
|
for (uint8_t i = 0; i < 3; i++) {
|
||||||
SHOW_BOOL;
|
SHOW_BOOL_INT;
|
||||||
boolean++;
|
boolean++; integer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n* 2:\n");
|
printf("\n* 2:\n");
|
||||||
boolean *= 2;
|
boolean *= 2; integer *= 2;
|
||||||
SHOW_BOOL;
|
SHOW_BOOL_INT;
|
||||||
|
|
||||||
printf("\n<< 1:\n");
|
printf("\n<< 1:\n");
|
||||||
boolean <<= 1;
|
boolean <<= 1; integer <<= 1;
|
||||||
SHOW_BOOL;
|
SHOW_BOOL_INT;
|
||||||
|
|
||||||
printf("\n/ 2:\n");
|
printf("\n/ 2:\n");
|
||||||
boolean /= 2;
|
boolean /= 2; integer /= 2;
|
||||||
SHOW_BOOL;
|
SHOW_BOOL_INT;
|
||||||
|
|
||||||
printf("\n^ 0x10:\n");
|
printf("\n^ 0x10:\n");
|
||||||
boolean ^= 0x10;
|
boolean ^= 0x10; integer ^= 0x10;
|
||||||
SHOW_BOOL;
|
SHOW_BOOL_INT;
|
||||||
|
|
||||||
printf("\n>> 1:\n");
|
printf("\n>> 1:\n");
|
||||||
boolean >>= 1;
|
boolean >>= 1; integer >>= 1;
|
||||||
SHOW_BOOL;
|
SHOW_BOOL_INT;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user