Apparently (all the uppercase ones make it hard to read), functions replace the internal ordering of bytes of values ​​that occupy 2 or 4 bytes. For instance:
UTIL_htons(0x1234); UTIL_htonl(0x12345678);
I have no idea how to write them to Delphi ...
I hope they are already written, and the Delphi library uses them with some name. Check your documentation.
Edit
nResult = ( (pBuffer[ 0 ] << 8) & 0xFF00 ) | ( pBuffer[ 1 ] & 0x00FF );
in this line
pBuffer[0] is the first element of the pBuffer array
pBuffer[0] << 8 shifts this value 8 bits to the left (0x12 becomes 0x1200)
(...) & 0xFF00 is redundant: it resets the rightmost 8 bits
In pBuffer[1] & 0x00FF , only the pBuffer[1] & 0x00FF 8 bits are stored (therefore, 0x1234 becomes 0x0034)
Another operation | is dimensional or
( ... & 0xFF00) | ( ... & 0xFF00) ( ... & 0xFF00) | ( ... & 0xFF00) are the leftmost 8 bits of the first part and the rightmost 8 bits of the second part.
Edit: hto * / * toh naming
The htonl , htons , ntohl , ntohs in C are used to convert values ​​between the host and network byte order.
The byte order is not necessarily different (the byte order over the network is byte), so the first part of the function must check whether the host byte order is small or big-endian before performing the swaps ... or the check was performed earlier in a program that uses functions that you posted.
source share