Good morning,
i am new to B4A and already with a Problem.
I can not find out how Byte Arrays are working, may someone can help ?
I have to convert the parity and find the checksum.
in vb.net i use this function:
Private Function AddParity(ByVal _in As String) As Byte()
Dim item As Byte = &HFF
Dim p_par As Byte = &HD
Dim list As New List(Of Byte)
Dim encoding As New ASCIIEncoding
Dim num2 As Byte
For Each num2 In encoding.GetBytes((_in & Chr(10) & Chr(10) & Chr(10)))
item = CByte((item Xor num2))
list.Add(num2)
Next
item = CByte((item Xor p_par))
list.Add(p_par)
list.Add(item)
Return list.ToArray
End Function
wich is working fine.
in B4A i am struggeling with the this:
Sub AddParity(Inn As String) As Byte()
Dim bconv As ByteConverter
Dim item As Byte
item =0xFF ' &H7F
Dim p_par As Byte = 0x0d
Dim List1() As Byte
Dim encodeing() As Byte
encodeing = (Inn & Chr(10) & Chr(10) & Chr(10)).getbytes("ASCII")
'Dim num2 As Byte
For Each num2 As Byte In encodeing
item = Bit.Xor(item, num2)
List1.Add(num2)
Next
item = Bit.Xor( item , p_par)
List1.Add(p_par)
List1.Add(item)
Return List1
End Sub
the result from this function should send data to a Serial device by
I think the byte type is signed, not unsigned. It is because that is what is used in java. I think an int, might be used since the positive range goes to 32,767, and the byte as positive only to 127. I have not tried myself.