Dim inline as JavaObject
....
inline=Me
Dim value As Int = 23
' params = Value,bit start, bit end (inclusive)
Log(inline.RunMethod("getBits",Array(value,0,2)))
Log(inline.RunMethod("getBits",Array(value,3,5)))
....
#if java
public static byte getBits(int v,int st,int end){
byte res = 0;
for(int a=st;a<=end;a++){
res += (byte)(1<<a);
}
return (byte)((res & v)>>st);
}
#end if
...
Log(getBits(value,0,2))
Log(getBits(value,4,6))
...
Sub getBits(v As Int,bitStart As Int,bitEnd As Int) As Int
Dim res As Int = 0
For a = bitStart To bitEnd
res = res + Power(2,a)
Next
Return (Bit.ShiftRight(Bit.And(v,res),bitStart))
End Sub
Sub GetBits(v As Int,bitStart As Int,bitEnd As Int) As Byte
Dim i1 As Int = Bit.And(Bit.ShiftLeft(v, 7 - bitEnd), 0xff)
Return Bit.UnsignedShiftRight(i1, bitStart + 7 - bitEnd)
End Sub