線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2377
推到 Plurk!
推到 Facebook!

請問數字的and 運算

答題得分者是:Stallion
washare
初階會員


發表:14
回覆:36
積分:35
註冊:2006-10-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-06-21 01:43:03 IP:203.204.xxx.xxx 訂閱
最近看了Virtual tree元件的source中有一句
TreeNodeSize = (SizeOf(TVirtualNode) 3) and not 3;

其中TVirtualNode是一個record,想問一下 上面這句的意思
看起來是數字做and運算,但not 3不知代表什麼
如果是5 and not 3, 又會得到什麼值呢?
不知有沒有大大能做個詳解,謝謝。



TVirtualNode = packed record
Index, // index of node with regard to its parent
ChildCount: Cardinal; // number of child nodes
NodeHeight: Word; // height in pixels
States: TVirtualNodeStates; // states describing various properties of the node (expanded, initialized etc.)
Align: Byte; // line/button alignment
CheckState: TCheckState; // indicates the current check state (e.g. checked, pressed etc.)
CheckType: TCheckType; // indicates which check type shall be used for this node
Dummy: Byte; // dummy value to fill DWORD boundary
TotalCount, // sum of this node, all of its child nodes and their child nodes etc.
TotalHeight: Cardinal; // height in pixels this node covers on screen including the height of all of its
// children
// Note: Some copy routines require that all pointers (as well as the data area) in a node are
// located at the end of the node! Hence if you want to add new member fields (except pointers to internal
// data) then put them before field Parent.
Parent, // reference to the node's parent (for the root this contains the treeview)
PrevSibling, // link to the node's previous sibling or nil if it is the first node
NextSibling, // link to the node's next sibling or nil if it is the last node
FirstChild, // link to the node's first child...
LastChild: PVirtualNode; // link to the node's last child...
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
end;


Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-06-21 16:28:34 IP:211.22.xxx.xxx 未訂閱
應該學過真值表吧?如果沒有就很奇怪了?使用Debugger內的Run->Evaluate/Modify也可以算出來。
0101 // 5
0011 // 3
--------------
1100 // not 3 = 12
0101 // 5
------------------------------
0100 // 5 and not 3 = 4
washare
初階會員


發表:14
回覆:36
積分:35
註冊:2006-10-17

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-06-21 20:14:51 IP:203.204.xxx.xxx 訂閱
感恩,因為是半路出家的,粉多基礎的都沒學過。@@"
washare
初階會員


發表:14
回覆:36
積分:35
註冊:2006-10-17

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-06-21 20:33:31 IP:203.204.xxx.xxx 訂閱
想順便問一下 TreeNodeSize = (SizeOf(TVirtualNode) 3) and not 3這句寫成這樣的用意,說實在的我平常寫程式最多會用到數字運算而矣,再來就是羅輯判斷時才會用到and和not,而這邊似乎是對數字做and和not,這就讓我這外行人看的有點頭暈,但看source時又偶爾會看到這種表達式,真希望能夠弄懂這是什麼情況,或者可看那一方面的主題文章能夠了解這種表達式,還望各位先進提供一點線索,謝謝。
編輯記錄
washare 重新編輯於 2007-06-21 20:41:55, 註解 無‧
syntax
尊榮會員


發表:26
回覆:1139
積分:1258
註冊:2002-04-23

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-06-26 22:08:29 IP:61.64.xxx.xxx 訂閱

xxxx and not 3 幾乎就是 xxx := xxx - 3; 除了沒有借位

===================引 用 washare 文 章===================
想順便問一下TreeNodeSize = (SizeOf(TVirtualNode) 3) and not 3這句寫成這樣的用意,說實在的我平常寫程式最多會用到數字運算而矣,再來就是羅輯判斷時才會用到and和not,而這邊似乎是對數字做and和not,這就讓我這外行人看的有點頭暈,但看source時又偶爾會看到這種表達式,真希望能夠弄懂這是什麼情況,或者可看那一方面的主題文章能夠了解這種表達式,還望各位先進提供一點線索,謝謝。
編輯記錄
syntax 重新編輯於 2007-06-26 22:09:11, 註解 無‧
Kingron
中階會員


發表:1
回覆:51
積分:60
註冊:2005-09-14

發送簡訊給我
#6 引用回覆 回覆 發表時間:2007-07-15 03:19:36 IP:125.89.xxx.xxx 訂閱
这句代码的本意是把TreeNodeSize按4字节边界对齐。
不知道我的说法是否正确。

===================引 用 washare 文 章===================
最近看了Virtual tree元件的source中有一句
TreeNodeSize = (SizeOf(TVirtualNode) 3) and not 3;
------
超级猛料:http://kingron.delphibbs.com
Kingron
中階會員


發表:1
回覆:51
積分:60
註冊:2005-09-14

發送簡訊給我
#7 引用回覆 回覆 發表時間:2007-07-15 03:28:57 IP:125.89.xxx.xxx 訂閱
补充修正以下:
上面的代码,永远是返回TreeNodeSize的4字节对齐边界的,该结构的地址的右4字节边界地址
===================引 用 Kingron 文 章===================
这句代码的本意是把TreeNodeSize按4字节边界对齐。
不知道我的说法是否正确。

===================引 用 washare 文 章===================
最近看了Virtual tree元件的source中有一句
TreeNodeSize = (SizeOf(TVirtualNode) 3) and not 3;
------
超级猛料:http://kingron.delphibbs.com
編輯記錄
Kingron 重新編輯於 2007-07-15 03:30:50, 註解 無‧
系統時間:2024-04-27 3:10:30
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!