I'm struggling a bit with data types when I mix types and do maths.. I'm trying to create a circular buffer to handle my received bluetooth data.
Looking at the code above, when I step through in debug and OutBufRef = 6 and I call PeepByte(4), the value that ends up in newRef is 1 (just after I pass the "this is the offending line" point.
So it's a char (16bit unsigned value) that gets a value of 1, when signed 32bit with the value of 6 gets added to a signed 8 bit with the value of 4. I know its a horrible mix of types, but the outcome is still surprising to me and I'd like to definitively understand what I can or can't do with regards mixing types and basic maths.
Off to scour the manual.. thanks.
B4X:
Dim OutBufRef As Int = 0 '(this is in process globals)
B4X:
Sub PeepByte (indx As Char)As Byte
Dim val As Byte
Dim newRef As Char
newRef = OutBufRef + indx 'This is the offending line
If newRef >= 128 Then
newRef = newRef - 128
End If
val = InBuffer(newRef)
Return val
End Sub
Looking at the code above, when I step through in debug and OutBufRef = 6 and I call PeepByte(4), the value that ends up in newRef is 1 (just after I pass the "this is the offending line" point.
So it's a char (16bit unsigned value) that gets a value of 1, when signed 32bit with the value of 6 gets added to a signed 8 bit with the value of 4. I know its a horrible mix of types, but the outcome is still surprising to me and I'd like to definitively understand what I can or can't do with regards mixing types and basic maths.
Off to scour the manual.. thanks.