Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

bitwsie and + - swap - explain the output  RSS feed

 
Kalpesh Soni
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Roel De Nijs
Marshal
Posts: 10995
161
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags next time you post a code snippet
 
Roel De Nijs
Marshal
Posts: 10995
161
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the outputs you don't understand?

Let's start with swapPlus-method and add some more debugging info:


The output is as follows:
i[2147483646] j[2]
i[-2147483648] j[2]
i[-2147483648] j[2147483646]
i[2] j[2147483646]

 
Kalpesh Soni
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was reading some article and someone said A | B, A ^ B, A ^ B swaps variables without tempraroay 3rd var

but it doesnt, you have to use 3 XORs
 
Roel De Nijs
Marshal
Posts: 10995
161
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kalpesh Soni wrote:I was reading some article and someone said A | B, A ^ B, A ^ B swaps variables without tempraroay 3rd var

Indeed variables aren't swapped, but maybe that's a typo.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!