CodeItBetter Programming Another VB Programming Blog

How to determine if a number is even or odd (True for Odd; False for Even) (in three ways)

Posted on August 25, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'Math - How to determine if a number is even or odd (True for Odd; False for Even) (in three ways)
'Method 1:

Public Function IsEven(ByVal I As Long) As Boolean
   IsEven = Not -(i And 1)
End Function
 
'Method 2:

Public Function IsOdd(ByVal I As Long) As Boolean
   IsOdd = -(i And 1)
End Function
 
'Method 3:

Public Function IsOdd(ByVal lngNumber As Long) As Boolean
    IsOdd = (lngNumber Mod 2) <> 0
End Function
Filed under: Math Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.