C printing bits

前端 未结 5 1834
死守一世寂寞
死守一世寂寞 2020-12-03 15:14

I am trying to write a program in C that prints bits of int. for some reason i get wrong values,

void printBits(unsigned int num){
    unsigned int size = si         


        
5条回答
  •  醉梦人生
    2020-12-03 15:28

    You are calculating the result correctly, but you are not printing it right. Also you do not need a second loop:

    for(;i

    If you'd like to show off, you could replace the conditional with two exclamation points:

    printf("%u ", !!(num&maxPow));
    

提交回复
热议问题