danilom

inverte bits

Sep 8th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void dtob(unsigned int n);
  4.  
  5. int main(void) {
  6.        
  7.         dtob((char)-100);
  8.         printf("%p\n", (char)-100);
  9.         dtob((unsigned char)-100);
  10.         printf("%p\n", (unsigned char)-100);
  11.         dtob((short int)-100);
  12.         printf("%p\n", (short int)-100);
  13.         dtob((unsigned short int)-100);
  14.         printf("%p\n", (unsigned short int)-100);
  15.         dtob((int)-100);
  16.         printf("%p\n", (int)-100);
  17.         dtob((unsigned int)-100);
  18.         printf("%p\n", (unsigned int)-100);
  19.         return 0;
  20. }
  21.  
  22. int invertebits(x, p, n) unsigned x, p, n; {
  23.         //while(n--)x>>--p&1?x&=~(1<<p):(x|=1<<p);
  24.         return x^~(~0<<n)<<p-n;
  25. }
  26.  
  27. void dtob(unsigned int n) {
  28.         char i=0;
  29.         do{putchar((n>>31&1)+'0');}while((n<<=1)|++i<32);
  30.         putchar(10);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment