Bit.ParseInt issue

walterf25

Expert
Hello All, i'm having some difficulties understanding the Bit.ParseInt function, i have an array of 9 bytes that i need to send to a bluetooth module, this is the byte array i need to send. I need to have each byte in a spinner like so.

B4X:
``````spinner1.Add("A6")

I'm trying to parse the strings into bytearrays like so.

B4X:
``````Sub btnsend_click
Dim bytes() As Byte = Array As Byte(Bit.ParseInt(spinner1.GetItem(0), 16), Bit.ParseInt(spinner2.GetItem(0), 16), Bit.ParseInt(spinner3.GetItem(0), 16), _
Bit.ParseInt(spinner4.GetItem(0), 16), Bit.ParseInt(spinner5.GetItem(0), 16), Bit.ParseInt(spinner6.GetItem(0), 16), Bit.ParseInt(spinner7.GetItem(0), 16))
'Bit.ParseInt(spinner8.GetItem(0), 16, Bit.ParseInt(spinner9.GetItem(0), 16))
For i = 0 To bytes.Length - 1
Log(bytes(i))
Next
End Sub``````

the problem is that when i log the values i get this
-90
41
127
-67
-52
18
-114
how does the Hex number "A6" gets converted to -90 that does not make sense, Hex "A6" is decimal 166, has anyone else seen this, the only numbers that seem correct are "7F" and "BD" what's going on, can anyone explain what's going on here?

thedesolatesoul

Expert
how does the Hex number "A6" gets converted to -90 that does not make sense, Hex "A6" is decimal 166, has anyone else seen this, the only numbers that seem correct are "7F" and "BD" what's going on, can anyone explain what's going on here?
A6 = 166 (unsigned) = -90 (signed)
(Anything over 128 will have the MSB set, if treated as signed, the sign bit will be set for any value over 80)

walterf25

Expert
Bit.ParseInt

Ahhh, ok that makes sense now :sign0013:

Thanks, i forgot about that, duh!

Cheers,
Walter

Replies
6
Views
576
Replies
4
Views
981
Replies
13
Views
987
Replies
1
Views
2K
Replies
7
Views
1K