December 04, 2020, 11:50:21 AM

Author Topic: [bb] Integer swapping by BlitzSupport [ 1+ years ago ]  (Read 574 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Integer swapping by BlitzSupport [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Integer swapping
Author : BlitzSupport
Posted : 1+ years ago

Description : Again, got this from someone else -- no idea who, sorry!

The second version came from [a http://www.cfxweb.net/phpbb/viewtopic.php?topic=78&forum=14]here[/a].


Code :
Code: BlitzBasic
  1. a = 1
  2. b = 2
  3.  
  4. Print a
  5. Print b
  6.  
  7. Print
  8.  
  9. a=a Xor b
  10. b=a Xor b
  11. a=a Xor b
  12.  
  13. Print a
  14. Print b
  15.  
  16. ; And another version...
  17.  
  18. Print
  19.  
  20. a = 1
  21. b = 2
  22.  
  23. Print a
  24. Print b
  25. Print
  26.  
  27. a = a + b
  28. b = a - b
  29. a = a - b
  30.  
  31. Print a
  32. Print b
  33.  


Comments :


itsdanreed(Posted 1+ years ago)

 Pretty clever.


Czar Flavius(Posted 1+ years ago)

 On modern processors the Xor swap is slower than using a temp variable.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal