Help with using bits in an integer

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi All

I have a form with about 20 check boxes and I want to persist their state to
a single integer. That is to say, I want to set their Checked property to a
particular bit value contained in an integer (32 possible values)
The following methods (translated from VB6) should help with this?:
Public Sub BitSet(ByVal iValue As Integer, ByVal Bitnum As Integer, ByVal
State As Boolean)

Try

If State Then

iValue = iValue Or CType(2 ^ Bitnum, Integer)

Else

iValue = iValue And Not CType(2 ^ Bitnum, Integer)

End If

Catch : End Try

End Sub

Public Function BitGet(ByVal iValue As Integer, ByVal Bitnum As Integer) As
Boolean

Return CBool(iValue And CType(2 ^ Bitnum, Integer))

End Function

However, there could be some better way to do this in VB.Net (2005). The
whole thing is about user permissions for an inhouse application.

I have had a look at the BitArray class, but find myself somewhat confused
on how to persist this to a database, or read back that value.

If someone could give me some help or a hint, I would be most appreciative.

Thank you


.