Help with using bits in an integer
- From: "Harry Strybos" <harry@xxxxxxxxxxxxx>
- Date: Mon, 02 Oct 2006 06:28:56 GMT
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
.
- Follow-Ups:
- Re: Help with using bits in an integer
- From: GhostInAK
- Re: Help with using bits in an integer
- From: Robinson
- Re: Help with using bits in an integer
- Prev by Date: Re: Citrix, VB.NET and Repaint
- Next by Date: Re: vb6 to vb.net migration
- Previous by thread: DataGridView column format
- Next by thread: Re: Help with using bits in an integer
- Index(es):