我正在將一些C代碼轉換爲Delphi。有人可以向我解釋這條線的含義嗎?這行代碼是什麼意思?
nResult = ((pBuffer[ 0 ] << 8) & 0xFF00)
| (pBuffer[ 1 ] & 0x00FF);
下面是代碼的上下文的其餘部分:
USHORT UTIL_htons(USHORT hostshort)
{
PUCHAR pBuffer;
USHORT nResult;
nResult = 0;
pBuffer = (PUCHAR)&hostshort;
nResult = ((pBuffer[ 0 ] << 8) & 0xFF00)
| (pBuffer[ 1 ] & 0x00FF);
return(nResult);
}
USHORT UTIL_ntohs(USHORT netshort)
{
return(UTIL_htons(netshort));
}
ULONG UTIL_htonl(ULONG hostlong)
{
PUCHAR pBuffer;
ULONG nResult;
UCHAR c, *pResult;
pBuffer = (PUCHAR)&hostlong;
if(!pBuffer)
{
return(0L);
}
pResult = (UCHAR *)&nResult;
c = ((UCHAR *)pBuffer)[ 0 ];
((UCHAR *)pResult)[ 0 ] = ((UCHAR *)pBuffer)[ 3 ];
((UCHAR *)pResult)[ 3 ] = c;
c = ((UCHAR *)pBuffer)[ 1 ];
((UCHAR *)pResult)[ 1 ] = ((UCHAR *)pBuffer)[ 2 ];
((UCHAR *)pResult)[ 2 ] = c;
return(nResult);
}
ULONG UTIL_ntohl(ULONG netlong)
{
return(UTIL_htonl(netlong));
}
在此先感謝 博揚
你嘗試過這麼遠嗎?你堅持什麼?我們喜歡幫助自我幫助的人,而不僅僅是爲他們工作。 – Oded 2010-11-13 21:02:43
好的。重述這個問題。有人可以向我解釋此行的含義nResult =((pBuffer [0] << 8)&0xFF00) | (pBuffer [1]&0x00FF); – 2010-11-13 21:11:47
我厚引用的行是自我解釋。它從一個緩衝區元素獲取8位,然後從另一個緩衝區獲得8位,然後將它們連接在一起。 – Vovanium 2010-11-14 00:17:51