#include <stdio.h>
#include <string.h>
typedef enum {
ONE = 0x1,
TWO = 0x2,
THREE = 0x4,
FOUR = 0x8,
} options;
static const char *byte_to_binary (int x)
{
int z;
static char b[9];
b[0] = '\0';
for (z = 256; z > 0; z >>= 1)
{
strcat(b
, ((x
& z
) == z
) ? "1" : "0"); }
return b;
}
int main(int argc, char *argv[])
{
options o = 0;
printf( "%s\n", byte_to_binary
(o
)); o |= ONE;
printf( "%s\n", byte_to_binary
(o
)); o |= TWO;
printf( "%s\n", byte_to_binary
(o
)); o |= THREE;
printf( "%s\n", byte_to_binary
(o
)); o |= FOUR;
printf( "%s\n", byte_to_binary
(o
)); o &= ~FOUR;
printf( "%s\n", byte_to_binary
(o
)); o &= ~THREE;
printf( "%s\n", byte_to_binary
(o
)); o &= ~TWO;
printf( "%s\n", byte_to_binary
(o
)); o &= ~ONE;
printf( "%s\n", byte_to_binary
(o
));
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCnR5cGVkZWYgZW51bSB7CiBPTkUgPSAweDEsCiBUV08gPSAweDIsCiBUSFJFRSA9IDB4NCwKIEZPVVIgPSAweDgsCn0gb3B0aW9uczsKCnN0YXRpYyBjb25zdCBjaGFyICpieXRlX3RvX2JpbmFyeSAoaW50IHgpCnsKICBpbnQgejsKICBzdGF0aWMgY2hhciBiWzldOwogIGJbMF0gPSAnXDAnOwoKICBmb3IgKHogPSAyNTY7IHogPiAwOyB6ID4+PSAxKQogICAgewogICAgc3RyY2F0KGIsICgoeCAmIHopID09IHopID8gIjEiIDogIjAiKTsKICAgIH0KCiAgcmV0dXJuIGI7Cn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pCnsKICBvcHRpb25zIG8gPSAwOwogIHByaW50ZiggIiVzXG4iLCBieXRlX3RvX2JpbmFyeShvKSk7CiAgbyB8PSBPTkU7CiAgcHJpbnRmKCAiJXNcbiIsIGJ5dGVfdG9fYmluYXJ5KG8pKT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