Android Question Bit.AND and Bit.Or for Longs

Discussion in 'Android Questions' started by Robert Valentino, May 14, 2015.

  1. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    Does anyone have a library that will allow modifying then bits in long values

    I want to be able to use a long (64 bits) for flags and the Bit operations only return longs.

    Has anyone made a library that works with longs?

    BobVal
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Create a class module with this code:
    Code:
    Sub Class_Globals
       
    Private jo As JavaObject
    End Sub

    Public Sub Initialize
       jo = Me
    End Sub

    public Sub AndLong (N1 As Long, N2 As Long) As Long
       
    Return jo.RunMethod("andLong"Array(N1, N2))
    End Sub

    public Sub OrLong (N1 As Long, N2 As Long) As Long
       
    Return jo.RunMethod("orLong"Array(N1, N2))
    End Sub

    #If JAVA
    public long andLong (long n1, long n2) {
       return n1 & n2;
    }
    public long orLong (long n1, long n2) {
       return n1 | n2;
    }
    #End If
     
  3. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    Thanks so much
     
    Last edited: May 14, 2015
  4. Marc De Loose

    Marc De Loose Member Licensed User

    I think this is related.
    I am using this code to read flags

    Code:
    Sub GetBit(b As Byte, index As Int) As Boolean
        
    Dim t As Byte = Bit.ShiftLeft(1, index)
        
    Return Bit.And(b, t) = t
    End Sub
    But now I need to read the flags of a bitfield that is basicaly an unsigned int (max value 4294967295)

    Any pointers on how I can change the Sub GetBIt so I can Use it with unsigned and unsigned int (I guess a long should work too)?

    That would be a great help.

    thx
     
  5. Marc De Loose

    Marc De Loose Member Licensed User

    I think I figured it out. This seems to be working:
    Code:
    Sub Class_Globals
        
    Private jo As JavaObject
    End Sub

    Public Sub Initialize
        jo = Me
    End Sub

    public Sub AndLong (N1 As Long, N2 As Long) As Long
        
    Return jo.RunMethod("andLong"Array(N1, N2))
    End Sub

    public Sub OrLong (N1 As Long, N2 As Long) As Long
        
    Return jo.RunMethod("orLong"Array(N1, N2))
    End Sub

    public Sub ShiftLeftLong (N1 As Long, Index As Int) As Long
        
    Return jo.RunMethod("shiftLeftLong",Array(N1,Index))
    End Sub

    #If JAVA
    public long andLong (long n1, long n2) {
       return n1 & n2;
    }
    public long orLong (long n1, long n2) {
       return n1 | n2;
    }

    public long shiftLeftLong (long n1, int ind) {
        return n1 << ind;
    }
    #End If
    and the new GetBitLong:

    Code:
    sub GetBitLong (l As Long, index As Int) As Boolean
        
    Dim t As Long = longbit.ShiftLeftLong(1,index)
        
    Return longbit.AndLong(l,t) = t
    End Sub
     
  6. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice