全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2562
推到 Plurk!
推到 Facebook!

邏輯運運算元的相關請教

尚未結案
sumeihua
一般會員


發表:9
回覆:13
積分:4
註冊:2004-04-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-24 17:10:31 IP:63.84.xxx.xxx 未訂閱
請教各位前進:    Delphi提供的六種邏輯運運算元: Not, And, Or, Xor, Shl, Shr, 對其函義不甚理解, 能否勞煩前進指教其函義, 謝謝!    ====================================== 誠心向學! 肯請指教! ======================================
------
======================================
誠心向學! 肯請指教!
======================================
yachanga
資深會員


發表:24
回覆:335
積分:296
註冊:2003-09-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-24 18:08:37 IP:61.230.xxx.xxx 未訂閱
Hi sumeihua: 請參考Delphi Help, 可分為Bitwise and Boolean 運算: 一般來說, shl, shr 用來作位元位移的,我也不常用.. 例如 000011(3) shr 1(向右位移1位) 就變成 000001(1)    而 not, or, xor, and 我習慣用來判斷True/False (雖然可以用來作Bitwise) 假設有兩個A,B Boolean值
Not A,   Return True when A is False
A And B: Return true when A,B 都是True
A or B:  Return True when A,B只要有一個是True
A xor B: Return True when  A, B不同 boolean 值
===================================== The following logical operators perform bitwise manipulation on integer operands. For example, if the value stored in X (in binary) is 001101 and the value stored in Y is 100001, the statement Z := X or Y; assigns the value 101101 to Z. Operator Operation Operand types Result type Examples not bitwise negation integer integer not X and bitwise and integer integer X and Y or bitwise or integer integer X or Y xor bitwise xor integer integer X xor Y shl bitwise shift left integer integer X shl 2 shr bitwise shift right integer integer Y shl I =============================================================== The Boolean operators not, and, or, and xor take operands of any Boolean type and return a value of type Boolean. Operator Operation Operand types Result type Example not negation Boolean Boolean not (C in MySet) and conjunction Boolean Boolean Done and (Total > 0) or disjunction Boolean Boolean A or B xor exclusive disjunction Boolean Boolean A xor B These operations are governed by standard rules of Boolean logic. For example, an expression of the form x and y is True if and only if both x and y are True. 發表人 - yachanga 於 2004/04/24 18:23:20 發表人 - yachanga 於 2004/04/24 18:24:11
sumeihua
一般會員


發表:9
回覆:13
積分:4
註冊:2004-04-24

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-27 10:51:39 IP:63.84.xxx.xxx 未訂閱
感謝yachanga先進的講解.    只是我想請教的是邏輯運運算元, 而非布林運運算元. 我在參考書上看到這樣的例子, 只是說沒有解釋, 故以此例子來請教各位先進: Not: Not 5 [結果為250] 這個運運算元已經瞭解其原理了 And: 5 and 3 [結果為1] 請教... Or: 5 Or 3 [結果為7] 請教... Xor: 5 Xor 3 [結果為6] 請教... Shl: 5 Shl 3 [結果為40] 請教... shr: 5 Shr 3 [結果為0] 請教... 感謝! ====================================== 誠心向學! 肯請指教! ======================================
------
======================================
誠心向學! 肯請指教!
======================================
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-04-27 11:03:02 IP:202.39.xxx.xxx 未訂閱
引言: And: 5 and 3 [結果為1] 請教...
0000 0101 => 5 的 2 進位表示為 00000001 0000 0011 => 3 --------- => 做 and 運算 0000 0001 => 結果為 1
引言: Or: 5 Or 3 [結果為7] 請教...
0000 0101 => 5 0000 0011 => 3 --------- => 做 or 運算 0000 0111 => 結果為 7 xor 部份類推.
引言: Shl: 5 Shl 3 [結果為40] 請教...
0000 0101 => 5 shl 3 => 每個 bit 往左移 3 格 0010 1000 => 結果為 40 shr 部份類推. 發表人 - hagar 於 2004/04/27 11:12:42
sumeihua
一般會員


發表:9
回覆:13
積分:4
註冊:2004-04-24

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-04-27 11:55:47 IP:63.84.xxx.xxx 未訂閱
謝謝hagar兄的解答, 我明白了. 也謝謝yachanga兄的熱心.    ====================================== 誠心向學! 肯請指教! ======================================
------
======================================
誠心向學! 肯請指教!
======================================
系統時間:2024-05-16 9:35:42
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!