VB 2005 BitVector32

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SGFucw==?=

    #1

    VB 2005 BitVector32

    Hello,

    I need some help on the BitVector32 class.

    I'm trying to create a function like:

    Private Sub Function (ByVal Input as integer, ByVal Bitnr as integer,
    ByVal BitHigh as Boolean) As Integer

    Return Output
    End Function

    The function must return a new integer value, with the proper bitnumber set
    true or false.

    Thanks

    Hans


  • Henning Krause [MVP - Exchange]

    #2
    Re: VB 2005 BitVector32

    Hello Hans,

    you can do this with this function:

    Private Shared Function IsFlagSet(ByVal value As Integer, ByVal bitNr As
    Integer) As Boolean
    If ((bitNr < 0) OrElse (bitNr 31)) Then
    Throw New ArgumentOutOfRa ngeException("b itNr")
    End If
    Return (((value >bitNr) And 1) = 1)
    End Function

    Best regards,
    Henning Krause


    "Hans" <Hans@discussio ns.microsoft.co mwrote in message
    news:1C61776C-DFA1-4787-B977-CFE6FA3808BC@mi crosoft.com...
    Hello,
    >
    I need some help on the BitVector32 class.
    >
    I'm trying to create a function like:
    >
    Private Sub Function (ByVal Input as integer, ByVal Bitnr as integer,
    ByVal BitHigh as Boolean) As Integer
    >
    Return Output
    End Function
    >
    The function must return a new integer value, with the proper bitnumber
    set
    true or false.
    >
    Thanks
    >
    Hans
    >
    >

    Comment

    • =?Utf-8?B?SGFucw==?=

      #3
      Re: VB 2005 BitVector32

      Hello Henning,

      Thanks for your resaction,

      But i don't want to know if the bit is set or not.
      Sample:

      Private Sub Function SetBitInt32 (ByVal Input as integer, ByVal Bitnr as
      integer,
      ByVal BitHigh as Boolean) As Integer

      Dim Output as Integer
      Dim BV As New BitVector32(Inp ut)

      " Then set the Bitnr in the Input , BitHigh True or False"
      " Return the Output Integer"

      Return Output

      End Function

      I would like to use the BitVector32 class.


      Best regards,
      Hans

      "Henning Krause [MVP - Exchange]" wrote:
      Hello Hans,
      >
      you can do this with this function:
      >
      Private Shared Function IsFlagSet(ByVal value As Integer, ByVal bitNr As
      Integer) As Boolean
      If ((bitNr < 0) OrElse (bitNr 31)) Then
      Throw New ArgumentOutOfRa ngeException("b itNr")
      End If
      Return (((value >bitNr) And 1) = 1)
      End Function
      >
      Best regards,
      Henning Krause
      >
      >
      "Hans" <Hans@discussio ns.microsoft.co mwrote in message
      news:1C61776C-DFA1-4787-B977-CFE6FA3808BC@mi crosoft.com...
      Hello,

      I need some help on the BitVector32 class.

      I'm trying to create a function like:

      Private Sub Function (ByVal Input as integer, ByVal Bitnr as integer,
      ByVal BitHigh as Boolean) As Integer

      Return Output
      End Function

      The function must return a new integer value, with the proper bitnumber
      set
      true or false.

      Thanks

      Hans
      >
      >

      Comment

      • Henning Krause [MVP - Exchange]

        #4
        Re: VB 2005 BitVector32

        Hello,

        you can do this with your own function like this:

        Private Shared Function SetBit(ByVal value As Integer, ByVal bitNr As
        Integer, ByVal state As Boolean) As Integer
        If ((bitNr < 0) OrElse (bitNr &H1F)) Then
        Throw New ArgumentOutOfRa ngeException("b itNr")
        End If
        Dim mask As Integer = (CInt(1) << bitNr)
        If state Then
        value = (value Or mask)
        Else
        value = (value And Not mask)
        End If
        Return value
        End Function

        Best regards,
        Henning Krause


        "Hans" <Hans@discussio ns.microsoft.co mwrote in message
        news:D340BE06-05B3-440A-AD87-549463C7DB97@mi crosoft.com...
        Hello Henning,
        >
        Thanks for your resaction,
        >
        But i don't want to know if the bit is set or not.
        Sample:
        >
        Private Sub Function SetBitInt32 (ByVal Input as integer, ByVal Bitnr as
        integer,
        ByVal BitHigh as Boolean) As Integer
        >
        Dim Output as Integer
        Dim BV As New BitVector32(Inp ut)
        >
        " Then set the Bitnr in the Input , BitHigh True or False"
        " Return the Output Integer"
        >
        Return Output
        >
        End Function
        >
        I would like to use the BitVector32 class.
        >
        >
        Best regards,
        Hans
        >
        "Henning Krause [MVP - Exchange]" wrote:
        >
        >Hello Hans,
        >>
        >you can do this with this function:
        >>
        >Private Shared Function IsFlagSet(ByVal value As Integer, ByVal bitNr As
        >Integer) As Boolean
        > If ((bitNr < 0) OrElse (bitNr 31)) Then
        > Throw New ArgumentOutOfRa ngeException("b itNr")
        > End If
        > Return (((value >bitNr) And 1) = 1)
        >End Function
        >>
        >Best regards,
        >Henning Krause
        >>
        >>
        >"Hans" <Hans@discussio ns.microsoft.co mwrote in message
        >news:1C61776 C-DFA1-4787-B977-CFE6FA3808BC@mi crosoft.com...
        Hello,
        >
        I need some help on the BitVector32 class.
        >
        I'm trying to create a function like:
        >
        Private Sub Function (ByVal Input as integer, ByVal Bitnr as integer,
        ByVal BitHigh as Boolean) As Integer
        >
        Return Output
        End Function
        >
        The function must return a new integer value, with the proper bitnumber
        set
        true or false.
        >
        Thanks
        >
        Hans
        >
        >
        >>
        >>

        Comment

        • =?Utf-8?B?SGFucw==?=

          #5
          Re: VB 2005 BitVector32

          Hello,

          Thanks,

          Your function works great.

          But i would like to know how the bitvector32 class works.
          Can i have the same functionality with that class ?


          Best Regards,

          Hans


          "Henning Krause [MVP - Exchange]" wrote:
          Hello,
          >
          you can do this with your own function like this:
          >
          Private Shared Function SetBit(ByVal value As Integer, ByVal bitNr As
          Integer, ByVal state As Boolean) As Integer
          If ((bitNr < 0) OrElse (bitNr &H1F)) Then
          Throw New ArgumentOutOfRa ngeException("b itNr")
          End If
          Dim mask As Integer = (CInt(1) << bitNr)
          If state Then
          value = (value Or mask)
          Else
          value = (value And Not mask)
          End If
          Return value
          End Function
          >
          Best regards,
          Henning Krause
          >
          >
          "Hans" <Hans@discussio ns.microsoft.co mwrote in message
          news:D340BE06-05B3-440A-AD87-549463C7DB97@mi crosoft.com...
          Hello Henning,

          Thanks for your resaction,

          But i don't want to know if the bit is set or not.
          Sample:

          Private Sub Function SetBitInt32 (ByVal Input as integer, ByVal Bitnr as
          integer,
          ByVal BitHigh as Boolean) As Integer

          Dim Output as Integer
          Dim BV As New BitVector32(Inp ut)

          " Then set the Bitnr in the Input , BitHigh True or False"
          " Return the Output Integer"

          Return Output

          End Function

          I would like to use the BitVector32 class.


          Best regards,
          Hans

          "Henning Krause [MVP - Exchange]" wrote:
          Hello Hans,
          >
          you can do this with this function:
          >
          Private Shared Function IsFlagSet(ByVal value As Integer, ByVal bitNr As
          Integer) As Boolean
          If ((bitNr < 0) OrElse (bitNr 31)) Then
          Throw New ArgumentOutOfRa ngeException("b itNr")
          End If
          Return (((value >bitNr) And 1) = 1)
          End Function
          >
          Best regards,
          Henning Krause
          >
          >
          "Hans" <Hans@discussio ns.microsoft.co mwrote in message
          news:1C61776C-DFA1-4787-B977-CFE6FA3808BC@mi crosoft.com...
          Hello,

          I need some help on the BitVector32 class.

          I'm trying to create a function like:

          Private Sub Function (ByVal Input as integer, ByVal Bitnr as integer,
          ByVal BitHigh as Boolean) As Integer

          Return Output
          End Function

          The function must return a new integer value, with the proper bitnumber
          set
          true or false.

          Thanks

          Hans


          >
          >
          >
          >

          Comment

          • =?Utf-8?B?SGFucw==?=

            #6
            Re: VB 2005 BitVector32

            Hello Henning,

            Thanks for putting me in the right direction.

            This is my solution with the bitvector32 class.


            Public Function SetInt32Bit(ByV al iInputInt32 As Integer, ByVal iBitNr
            As Integer, ByVal State As Boolean) As Integer

            Dim output As Integer

            Dim myBit(31) As Integer

            For i As Integer = 0 To 31
            If i = 0 Then
            myBit(i) = BitVector32.Cre ateMask()
            Else
            myBit(i) = BitVector32.Cre ateMask(myBit(i - 1))
            End If
            Next

            If State = True Then
            output = iInputInt32 Or myBit(iBitNr)
            Else
            output = iInputInt32 And Not myBit(iBitNr)
            End If


            Return output

            End Function

            Best regards,

            Hans

            "Henning Krause [MVP - Exchange]" wrote:
            Hello,
            >
            you can do this with your own function like this:
            >
            Private Shared Function SetBit(ByVal value As Integer, ByVal bitNr As
            Integer, ByVal state As Boolean) As Integer
            If ((bitNr < 0) OrElse (bitNr &H1F)) Then
            Throw New ArgumentOutOfRa ngeException("b itNr")
            End If
            Dim mask As Integer = (CInt(1) << bitNr)
            If state Then
            value = (value Or mask)
            Else
            value = (value And Not mask)
            End If
            Return value
            End Function
            >
            Best regards,
            Henning Krause
            >
            >
            "Hans" <Hans@discussio ns.microsoft.co mwrote in message
            news:D340BE06-05B3-440A-AD87-549463C7DB97@mi crosoft.com...
            Hello Henning,

            Thanks for your resaction,

            But i don't want to know if the bit is set or not.
            Sample:

            Private Sub Function SetBitInt32 (ByVal Input as integer, ByVal Bitnr as
            integer,
            ByVal BitHigh as Boolean) As Integer

            Dim Output as Integer
            Dim BV As New BitVector32(Inp ut)

            " Then set the Bitnr in the Input , BitHigh True or False"
            " Return the Output Integer"

            Return Output

            End Function

            I would like to use the BitVector32 class.


            Best regards,
            Hans

            "Henning Krause [MVP - Exchange]" wrote:
            Hello Hans,
            >
            you can do this with this function:
            >
            Private Shared Function IsFlagSet(ByVal value As Integer, ByVal bitNr As
            Integer) As Boolean
            If ((bitNr < 0) OrElse (bitNr 31)) Then
            Throw New ArgumentOutOfRa ngeException("b itNr")
            End If
            Return (((value >bitNr) And 1) = 1)
            End Function
            >
            Best regards,
            Henning Krause
            >
            >
            "Hans" <Hans@discussio ns.microsoft.co mwrote in message
            news:1C61776C-DFA1-4787-B977-CFE6FA3808BC@mi crosoft.com...
            Hello,

            I need some help on the BitVector32 class.

            I'm trying to create a function like:

            Private Sub Function (ByVal Input as integer, ByVal Bitnr as integer,
            ByVal BitHigh as Boolean) As Integer

            Return Output
            End Function

            The function must return a new integer value, with the proper bitnumber
            set
            true or false.

            Thanks

            Hans


            >
            >
            >
            >

            Comment

            Working...