My understanding : my original byte is base 16 and i wanna convert to base 10 , i should use Bit.ParseInt(t(i),10) right?
on my log file
no, the bytes are stored as base 2. Your source code is using base 16, but the values are converted to base 2 during compiling.
there are only 2 bytes convert error at t(3) and t(6) why?
There is no error, it is just a misunderstanding of how Bytes work in Java and misuse of ParseInt().
Bytes are stored as signed values in the range of -128 to 127. If you try and assign a value higher than 127, it will be interpreted as a two's compliment value and stored as a negative value. The binary representation will be the same, but will be treated as a negative when used in math or printed to the screen. SO when you are storing 0x9c in a byte, it is stored as -100 instead.
ParseInt() is not for converting bytes to Ints, instead it is for converting strings to ints. Passing bytes, then converting to Int really does nothing except eat up processing cycles.
To correctly convert all the Bytes into Ints, you just need to cast to the correct type and mask the result with Bit.AND().
Dim t(10) As Byte
t(0)=0x00
t(1)=0x2e
t(2)=0x6a
t(3)=0x9c
t(4)=0x01
t(5)=0x00
t(6)=0x9f
t(7)=0x02
t(8)=0x06
t(9)=0x00
Dim i As Int
For i=0 To t.Length-1
Log(Bit.AND(t(i),0xFF))
Next
The Bit.AND takes an Int as its first parameter. We are passing a Byte, but it is internally cast to an Int. The 0xFF will strip off the sign bits, leaving the original value instead of its negative version.
Results:
0
46
106
156
1
0
159
2
6
0