?
Solved

Masking bits in VB.NET

Posted on 2005-04-26
4
Medium Priority
?
886 Views
Last Modified: 2012-06-27
Hello !

I'm doing a project wich I need to mask out bits from an integer value.

In VB6 i did this to make it work :

if bSum And 2 ^ 0 Then
 'Bit active
end if

But this way is not working in VB.Net

How can I make it work ?
0
Comment
Question by:haakons
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 13868425
It works for me...try this out:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim bSum As Integer
        Dim result As String

        bSum = 3
        If bSum And 2 ^ 0 Then
            result = "IS"
        Else
            result = "IS NOT"
        End If
        MsgBox("bitSum = " & bSum & "    Bit 1 " & result & " active")

        bSum = 2
        If bSum And 2 ^ 0 Then
            result = "IS"
        Else
            result = "IS NOT"
        End If
        MsgBox("bitSum = " & bSum & "    Bit 1 " & result & " active")
    End Sub
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13868429
What's wrong in VB.NET?  It works for me.

Bob
0
 

Author Comment

by:haakons
ID: 13870197
Can you make it work with option strict ?

Haakon
0
 

Author Comment

by:haakons
ID: 13870395
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim bSum As Integer
        Dim result As String

        bSum = 3
        If Convert.ToBoolean(bSum And Convert.ToInt32(2 ^ 0)) Then
            result = "IS"
        Else
            result = "IS NOT"
        End If

        MsgBox("bitSum = " & bSum & "    Bit 1 " & result & " active")

        bSum = 2
        If Convert.ToBoolean(bSum And Convert.ToInt32(2 ^ 0)) Then
            result = "IS"
        Else
            result = "IS NOT"
        End If

        MsgBox("bitSum = " & bSum & "    Bit 1 " & result & " active")

    End Sub

I found out how to make it work with option strict. Thank you for your help Bob.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question