CSC373/406: Integers: Tricks with bitwise ops [1/9] Previous pageContentsNext page

   int x = ...;
   int y = ...;
   // what do the following three lines do?
   x = x ^ y;
   y = x ^ y;
   x = x ^ y;

   // what about this?
   int fun (int x, int y, int z) {
     int xtru = (!!x) <<31 >>31;
     int xfls = ~xtru;
     return (xtru & y) | (xfls & z)
   }

   // How about this?
   int xtru = (~!x) + 1;
}

Previous pageContentsNext page