Delphi winsock函式解析(一)

2021-08-09 17:07:35 字數 1817 閱讀 5540

1、inet_addr:將乙個點分十進位制的ip轉換成乙個長整數型數(u_long型別)

例如:127.0.0.1 ——》 000000000100007f

2、inet_ntoa:返回

點分十進位制

的字串在

靜態記憶體

中的指標(將

網路位址轉換

成「.」點隔的字串格式)。

番外篇:

1、inttohex:將乙個值轉換成16進製制形式的字串。

引數說明: value 是被轉換的整數,,

digits 是指16進製制字串的位數。

示例:inttohex(30,1) 返回 1e

inttohex(30,4)返回 001e //佔的位數是4

inttohex(30,-3) 返回 1e

2、關於 lo、hi、loword、hiword

cardinal 是 4 位元組無符號的整型, 先看乙個例數:

cardinal 例數:

4277991664

按位元組劃分:

第四位元組

第三位元組

第二位元組

第一位元組

二進位制:

11111110

11111100

11111000

11110000

十六進製制:

fefc

f8f0

十進位制:

254252

248240

按雙位元組劃分:

高兩位低兩位

二進位制:

1111111011111100

1111100011110000

十六進製制:

fefc

f8f0

十進位制:

65276

63728

//可以用 lo 函式提取它的低位元組(也就是第乙個位元組)

const

c: cardinal = 4277991664;

begin

showmessagefmt('%d', [lo(c)]);

end;

//其實不使用 lo 函式, 通過 byte 型別轉換也可以獲取第乙個位元組

const

c: cardinal = 4277991664;

begin

showmessagefmt('%d', [byte(c)]);

end;

//hi 函式說是獲取高位位元組, 其實是獲取第二個位元組

const

c: cardinal = 4277991664;

begin

showmessagefmt('%d', [hi(c)]);

end;

//如果要獲取低兩位, 貌似應該有個 loword 函式; 確實有, 但它不是函式, 只是 word 型別的乙個別稱.

const

c: cardinal = 4277991664;

begin

showmessagefmt('%d', [loword(c)]);

showmessagefmt('%d', [word(c)]);  

end;

//hiword 函式是提取高兩位的

const

c: cardinal = 4277991664;

begin

showmessagefmt('%d', [hiword(c)]);

end;

說說 loword 和 hiword 的用途:

譬如在乙個滑鼠訊息的訊息引數 lparam 中存放著滑鼠位置. lparam 是 4 位元組的, 它的低兩位存放 x、高兩位存放 y ...

delphi winsock 注意事項

var form1 tform1 用來儲存socket的控制代碼 sock sock cardinal sa sockaddr in ws twsadata implementation procedure tform1.formcreate sender tobject begin sa.sin ...

函式基礎 匿名函式,函式,箭頭函式,立即執行函式

doctype html html lang en head meta charset utf 8 meta name viewport content width device width,initial scale 1.0 title document title head body body ...

函式 常見函式

def fib n if n 1 return 1if n 2 return 1return fib n 1 fib n 2 def hannuo n,a,b,c n 表示有n個盤子 a 代表第乙個塔,開始的塔 b 代表第二個塔,過渡塔 c 代表第三個塔,目標塔 d.在 中n 2,這個分支可以不要,...