How to print bits in c

前端 未结 5 1136
礼貌的吻别
礼貌的吻别 2021-01-21 10:30

I\'m writing a function to print bits in c, I\'m only allowed to use write function. my function doesn\'t work for other numbers.

void    print_bit         


        
5条回答
  •  礼貌的吻别
    2021-01-21 11:09

    If you want to print bits then used bitwise operator and you can do that...

    such example:

    for(i=31 ; i>=0 ; i--)
    {
      if(num & 1<< i) /* num & 1 << position
       printf("1 ");
      else 
       printf("0 ");
    }
    printf("\n");
    

提交回复
热议问题