Skip to content

Instantly share code, notes, and snippets.

@tylor
Created March 16, 2010 22:22
Show Gist options
  • Save tylor/334612 to your computer and use it in GitHub Desktop.
Save tylor/334612 to your computer and use it in GitHub Desktop.
Ruby bitwise swap:
a = 10
b = 3
print (a ^ b ^ a), "\n" # 3
print (b ^ a ^ b), "\n" # 10
PHP bitwise swap:
<?php
$a = 10;
$b = 3;
print ($a ^ $b ^ $a) . "\n"; // 3
print ($b ^ $a ^ $b) . "\n"; // 10
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment