Shift bitwise and display the result : Bit Shift « Data Type « C / ANSI-C






Shift bitwise and display the result

Shift bitwise and display the result
#include <stdio.h>

void show_binary(unsigned u);

int main(void)
{
  unsigned short u;

  u = 45678;

  show_binary(u);
  u = u << 1;
  show_binary(u);
  u = u >> 1;
  show_binary(u);

  return 0;
}

void show_binary(unsigned u)
{
  int n;

  for( n = 32768; n > 0; n = n / 2 )
    if(u & n) 
        printf("1 ");
    else 
        printf("0 ");

  printf("\n");
}


           
       








Related examples in the same category

1.A bit shift exampleA bit shift example
2.Use bit shift to calculate
3.Shift statement in for