Android Question misunderstanding problem with ByteConverter and AsyncStreams

WhoIsShmoove

Active Member
Licensed User
good evening everyone, I have a little misunderstanding problem with ByteConverter and AsyncStreams

I have for example 1 to 6 digits with a value of 1 to 999999 which gives in hexa
999999 -> F423F
99999 -> 1869F
9999 -> 270F
999 -> 3E7
99 -> 63
9 -> 9

I have to send this whole example with the value 999999

B4X:
Dim packet () As Byte = Array As Byte (0x5A, 0xA5, 0x06, 0x83, 0x00, 0x99, Hex0, Hex1, Hex2)

except that when I have the value 9 a decimal I end up with

B4X:
Dim packet () As Byte = Array As Byte (0x5A, 0xA5, 0x06, 0x83, 0x00, 0x99, Hex2)
so it's no longer good, he doesn't care

I said to myself I'm going to turn everything into a thong

B4X:
Dim origin As String = "000000"
Dim str As String = Value
Dim j As Int = str.Length
Final dim as string = origin.SubString2 (0.6-j) and value

Dim Hex0 As Int = final.SubString2 (0.2) '99
Dim Hex1 As Int = final.SubString2 (2,4) '99
Dim Hex2 As Int = final.SubString2 (4.6) '99

Dim packet () As Byte = Array As Byte (0x5A, 0xA5, 0x06, 0x83, 0x00, 0x99, Hex0, Hex1, Hex2)

but in this case my Hex0 = 63 Hex1 = 63 and Hex2 = 63 instead of Hex0 = 0F Hex1 = 42 and Hex2 = 3F

I must be able to get for example

999999 -> 0x0F, 0x42x 0x3F
99999 -> 0x01, 0x86, 0x9F
9999 -> 0x00, 0x27, 0x0F
999 -> 0x00, 0x03, 0xE7
99 -> 0x00, 0x00, 0x63
9 -> 0x00, 0x00, 0x09


I'm going around in circles and I don't understand how to go about getting the right result and the cut I want
if a charitable man could put me on the right track. Hoping to have been clear in my explanations
 

OliverA

Expert
Licensed User
B4X:
Dim bc As ByteConverter
Dim bytes() As Byte = bc.IntsToBytes(Array As Int(999999))
'As long as we feed IntsToBytes only one integer, we will get back 4 bytes. Since, in this case, the largest integer will
'be 999999, we can skip bytes(0) and only use bytes(1), bytes(2), and bytes(3)
Dim packet () As Byte = Array As Byte (0x5A, 0xA5, 0x06, 0x83, 0x00, 0x99, bytes(1), bytes(2), bytes(3))
 
Upvote 1

WhoIsShmoove

Active Member
Licensed User
B4X:
Dim bc As ByteConverter
Dim bytes() As Byte = bc.IntsToBytes(Array As Int(999999))
'As long as we feed IntsToBytes only one integer, we will get back 4 bytes. Since, in this case, the largest integer will
'be 999999, we can skip bytes(0) and only use bytes(1), bytes(2), and bytes(3)
Dim packet () As Byte = Array As Byte (0x5A, 0xA5, 0x06, 0x83, 0x00, 0x99, bytes(1), bytes(2), bytes(3))
thank you very much really at the top it works very very well and much simpler than my gas plant
 
Upvote 0
Top