Bit Mapping

johnadonaldson

Well-known member
Joined
Nov 9, 2005
Messages
48
Programming Experience
10+
Can someone show the simple way to bit masking under VB.NET. I have regesters that I need to be able to determine which bit has been set and which has not. I tryed this but with mixed results

Dim nMask as Integer
Dim nResult as Integer

nMask = &H111

nResult = nMask AND nInput

if nResult = &h01 then
.......


else if nResult = &02 then
.......

I then need to change a single bit in a integer such as if bit 3 is a 0 then make it a 1 and not
affect the other bits.
 
thanks all, got it figured out.

Dim sOut As String
If nOutMask And &H1 Then
If CheckBox1.Checked Then
Mask1 = Mask1 Or &H1
Else
Mask1 = Mask1 Xor &H1
End If
End If
sOut = "W 01 0074 002 " & Mask1
MainForm.SendRS232(sOut)

the routines looks at check boxes and sets the integer according to if the box is checked or unchecked.

 
Back
Top