Swap two integers without using a third


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Collections
Public Class Tester
Public Shared Sub Main

Dim firstValue As Integer
Dim secondValue As Integer

firstValue = 17
secondValue = 123
Console.WriteLine(“Before swap: {0}, {1}”,firstValue, secondValue)

firstValue = firstValue Xor secondValue
secondValue = firstValue Xor secondValue
firstValue = firstValue Xor secondValue
Console.WriteLine(“After swap: {0}, {1}”,firstValue, secondValue)
End Sub
End Class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s