Quantcast
Channel: User Alex Lop. - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Answer by Alex Lop. for Program to print all the bits of one byte union without using bitwise operators

$
0
0

Maybe the point of this task is to use arithmetic operations instead of the bitwise ones?Here is an example:

void printByteBits(unsigned char num){    const static int div[8] = {1, 2, 4, 8, 16, 32, 64, 128};    for (int i = 0; i < sizeof(div)/sizeof(div[0]); i++)    {        printf("Bit %d: %d\n", i, (num / div[i]) % 2);    }}

See the output here: https://godbolt.org/z/xUC663


Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>