su -c ‘rm -rf /mnt/proprietary’

November 12, 2009

Swapping two variables without using third variable – old trick

Filed under: Programming — krish @ 6:21 pm
Tags: , ,

Pretty old trick, used today in my php code :


// Swap the months if from-month selected is later than to-month
//if($frommon > $tomon){
// $tempmon = $frommon;
// $frommon = $tomon;
// $tomon = $tempmon;
//}
// Smarter way using X-OR
if($frommon > $tomon){
$frommon = $frommon ^ $tomon ^ ( $tomon = $frommon );
}

Blog at WordPress.com.