How to check if Nth bit of an integer number is set or not in VB.NET

1 Answer

0 votes
Imports System
				
Public Module Module1
	Public Sub Main()
		Dim num As Integer = 23 ' 00010111
        Dim bitposition As Integer = 4

        If ((1 << bitposition) And num) Then
            Console.WriteLine("bit {0} is set", bitposition)
        Else
            Console.WriteLine("bit {0} is not set", bitposition)
        End If
	End Sub
End Module
	
	
	

' run:
'
' bit 4 is set
'

 



answered Dec 16, 2023 by avibootz
...