Imports System
Public Class Program
Public Shared Function flipped_count(ByVal a As Integer, ByVal b As Integer) As Integer
Dim n As Integer = a Xor b
Dim count As Integer = 0
While n > 0
count += 1
n = n And (n - 1)
End While
Return count
End Function
Public Shared Sub Main()
Dim a As Integer = 7, b As Integer = 10
Console.WriteLine("a = " & Convert.ToString(a, 2).PadLeft(4, "0"c))
Console.WriteLine("b = " & Convert.ToString(b, 2))
Console.WriteLine("a ^ b = " & Convert.ToString(a Xor b, 2))
Console.Write(flipped_count(a, b))
End Sub
End Class
' run:
'
' a = 0111
' b = 1010
' a ^ b = 1101
' 3
'