Advertisement
Jonas_3k

/*- Bit a Bit @ Operações And Or e Xor -*/

Feb 2nd, 2012
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include<stdio.h>
  2. void binary(int y)
  3. {
  4.     int  temp;
  5.     putchar('\t');
  6.     for(temp = y ; temp ; temp /= 2 )
  7.     {
  8.         printf("%d",temp%2);
  9.     }
  10.     putchar(27);
  11.     putchar('\n');
  12.     return;
  13. }
  14.  
  15. int main()
  16. {
  17.     int x,y,z,temp;
  18.     x = 0;
  19.     y = 255;
  20.     z = 128;
  21.  
  22.     printf("\tLeitura em conceito asi%ctico inicio em %c\n\n",160,27);
  23.  
  24.     binary(y); /*- binário de y -*/
  25.  
  26.     printf("or");
  27.  
  28.     binary(z); /*- binário de z -*/
  29.  
  30.     x = y|z; /*- operação entre os bits -*/
  31.  
  32.     binary(x); /*- retorna o resultado -*/
  33.  
  34.     printf("\t________\n\tBinario = %d",x);
  35.  
  36.     new_line
  37.  
  38.     binary(y);
  39.  
  40.     printf("and");
  41.  
  42.     binary(z);
  43.  
  44.     x = y&z;
  45.  
  46.     binary(x);
  47.  
  48.     printf("\t________\n\tBinario = %d",x);
  49.  
  50.     new_line
  51.  
  52.     binary(y);
  53.  
  54.     printf("xor");
  55.  
  56.     binary(z);
  57.  
  58.     x = y^z;
  59.  
  60.     binary(x);
  61.  
  62.     printf("\t________\n\tBinario = %d",x);
  63.  
  64.     new_line
  65.  
  66.     printf("\n\tUnario :~\n");
  67.  
  68.     printf("Antes: \n");
  69.  
  70.     binary(y);
  71.  
  72.     printf("Depois :\n");
  73.  
  74.     binary(~y);
  75.  
  76.     printf("\n ~ %d := %d ",y,~y);
  77.  
  78.     printf("\n\t%d um bit de deslocamento %c esquerda: ",10,133);
  79.  
  80.     x = x = 10 >> 1;
  81.  
  82.     printf(" >> %d",x);
  83.  
  84.     printf("\n\t%d um bit de deslocamento %c direita: ",10,133);
  85.  
  86.     x = x = 10 << 1;
  87.  
  88.     printf(" << %d\n\n",x);
  89.  
  90.     scanf("%[^\n]");
  91.  
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement