I need to copy the bits of a byte (not the value) to an integer. The reason is that the byte received from elsewhere in fact is an unsigned byte. Based on the sample code I found I tried to do it as follows:
B4X:
For i = 0 To 7
bitresult=GetBit(Light,i)
Log(Light)
Log(bitresult)
intlight=SetBit(intlight,i,bitresult)
Next
and :
B4X:
Sub SetBit(b As Int, index As Int, on As Boolean) As Int
If on Then
Return Bit.Or(b, Bit.ShiftLeft(1, index))
Else
Return Bit.And(b, Bit.Not(Bit.ShiftLeft(1, index)))
End If
End Sub
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
However, it doesn't work; the value of intlight always remains 0x0.