I am converting some numbers to a string which will be inserted in a UDP Packet for transfer to an embedded device I am working on.
I am wondering what is the most efficient way to accomplish this goal and have come up with the following two methods.
Which one of these if more efficient and do you know of a better way?
Local Msg As String
Local OutID As Word
Local ChangeTime As Dword
Local x As Byte Ptr
Word to String:
x = VarPtr(OutID)
msg = Chr$(x[0]) & Chr$(x[1])
Or
Msg$ = Chr$(Lo(Byte, OutID)) & Chr$(Lo(Byte, OutID))
DWord to String:
x = VarPtr(ChangeTime)
msg = Chr$(x[0]) & Chr$(x[1]) & Chr$(x[3]) & Chr$(x[4])
Or
Msg$ = Chr$(Lo(Byte, (Lo(Word, ChangeTime))) & _
Chr$(Lo(Byte, (Hi(Word, ChangeTime))) & _
Chr$(Hi(Byte, (Lo(Word, ChangeTime))) & _
Chr$(Hi(Byte, (Hi(Word, ChangeTime)))
I am wondering what is the most efficient way to accomplish this goal and have come up with the following two methods.
Which one of these if more efficient and do you know of a better way?
Local Msg As String
Local OutID As Word
Local ChangeTime As Dword
Local x As Byte Ptr
Word to String:
x = VarPtr(OutID)
msg = Chr$(x[0]) & Chr$(x[1])
Or
Msg$ = Chr$(Lo(Byte, OutID)) & Chr$(Lo(Byte, OutID))
DWord to String:
x = VarPtr(ChangeTime)
msg = Chr$(x[0]) & Chr$(x[1]) & Chr$(x[3]) & Chr$(x[4])
Or
Msg$ = Chr$(Lo(Byte, (Lo(Word, ChangeTime))) & _
Chr$(Lo(Byte, (Hi(Word, ChangeTime))) & _
Chr$(Hi(Byte, (Lo(Word, ChangeTime))) & _
Chr$(Hi(Byte, (Hi(Word, ChangeTime)))
Comment