i.e., Hffffffff + H00000001 = H00000000. Es wird auch als "Rollover" oder "Wrap" bezeichnet. Wenn Sie auf dem PC Byte -Array zu 32 -Bit -Ganzzahl -Array 'memcpy' -Array' byte -orientiert werden, müssen Sie mit der Funktion 'htonl' invers < /p>
< /blockquote>
die Person, die dies geschrieben hat, auch einen Code -Snippet (VB) enthielt: < /p>
enthielt dies auch einen Code -Snippet (VB): < /p>
Code: Select all
Declare Function MemCpy& Lib "Kernel32" Alias "RtlMoveMemory" (pDest As Any, pFrom As Any, ByVal wBytes&)
Declare Function htonl& Lib "ws2_32.dll" (ByVal u&)
[...] note: already having '7of8' bytes in array b(0 to 377)
' get check sum complement :
Dim check As Long
MemCpy b(15), check, 4
check = htonl(check)
' compute check sum:
Dim i As Long, v(77) As Long, sum As Currency
MemCpy b(63), v(0), 78 * 4
For i = 0 To 77
sum = sum + htonl(v(i))
If sum > 2147483647@ Then sum = sum – 4294967296@ ' rollover highest bound
If sum < -2147483647@ Then sum = sum + 4294967296@ ' rollover lowest bound
Next i
' final control: adding sum and check should gives 0:
sum = sum + check
If sum > 2147483647@ Then sum = sum – 4294967296@ ' rollover highest bound
If sum < -2147483647@ Then sum = sum + 4294967296@ ' rollover lowest bound
If sum = 0@ Then
[...]