Re: Help with using bits in an integer
- From: GhostInAK <paco@xxxxxxxx>
- Date: Tue, 3 Oct 2006 06:08:48 +0000 (UTC)
Hello Harry,
Check out the BitConverter class.
-Boo
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
.
- References:
- Help with using bits in an integer
- From: Harry Strybos
- Help with using bits in an integer
- Prev by Date: Re: turning caps lock off
- Next by Date: VB2005 - Setup Project => Add an uninstall icon in 'All Programs' ?
- Previous by thread: Re: Help with using bits in an integer
- Next by thread: Setup.exe Bootstrapper
- Index(es):