yarsye 发表于 2010-6-1 09:31:50

白痴问个比较白痴的问题:在实际中我到底怎么样才会用到BitOR,BitAND,BitXOR?

我看了help file只是了解他们是按位“或”“与”运算,但是在实际中我到底怎么样才会用到呢?

xuanfeng1234567 发表于 2010-6-1 10:00:21

想要知道,想要提高,还是建议LZ多看看源码作品,自己再动手写作品。

yarsye 发表于 2010-6-1 10:08:26

我也想这样的啊 但是我每次写 都是我已经会的 不会的学的有点慢

caodongchun 发表于 2010-6-1 10:12:43

最主要的功能是简化语句

netegg 发表于 2010-6-1 10:22:34

google下"位与","位或"的概念

sxd 发表于 2010-6-2 14:28:57

属性集合 和 权限相关 的时候基本要用到

不过还是先顶一下楼上的蛋蛋

akmm88 发表于 2010-6-3 10:53:30

布尔代数是编程的必修课之一.
下面拿AU3的fileopen来解释下位操作
函数原型:
FileOpen ( "filename", mode )




Parameters

filename Filename of the text file to open.
mode Mode (read or write) to open the file in.
Can be a combination of the following:
0 = Read mode
1 = Write mode (append to end of file)
2 = Write mode (erase previous contents)
4 = Read raw mode
8 = Create directory structure if it doesn't exist (See Remarks).
16 = Force binary(byte) reading and writing mode with FileRead and FileWrite
32 = Use Unicode UTF16 Little Endian reading and writing mode. Reading does not override existing BOM
64 = Use Unicode UTF16 Big Endian reading and writing mode. Reading does not override existing BOM
128 = Use Unicode UTF8 reading and writing mode. Reading does not override existing BOM
Both write modes will create the file if it does not already exist. The folder path must already exist (except using mode '8' - See Remarks).

当我们要打开一个文件并重写,当文件不存在时自动建立.需使用
$mode=2+8
或者
$mode=10
也可以
$mode=BitOR(2,8)这样更直观些,如果在加一个属性按二进制,只需BitOR(2,8,16)
fileopen($filepath,$mode)
那么如果是我们自己的函数,在函数内该如何判断,参数里具有某些属性呢?
if BitAnd($mode,2)<>0'为重写模式

if BitAnd($mode,8)<>0 '
位是计算机内存能操作的最小单位.速度也是最快的.
;进行位运算得到32位的最大数
;得到的是负数,不知道AU3是否支持无符号整数.
$n=1
$n=BitShift($n,-31);将1左移31位,最高位=1
$n=BitOR( BitXOR($n,0),$n);进行异或后在进行或运算,将所有的位赋值为1
ConsoleWrite($n)

yarsye 发表于 2010-6-3 17:00:14

有点晕 没用过

pusofalse 发表于 2010-6-3 22:17:33

BitOR(10, 20) 举例。
先转成2进制,看起来更直观一些。比如10的2进制是1010,在前面补齐28个0(32位),20的2进制是10100,在前面补齐27个0,每位相对应。BitOR(10, 20)之后的结果是30,30的2进制11110。

b 00000000000000000000000000001010          d 10
b 00000000000000000000000000010100          d 20
----------------------------------------------------------------------
b 00000000000000000000000000011110          d 30

“按位相或”的意思是,对应位上有1则1,无1则0。

另外的“异”、“与”,你转成2进制,每位相对应,再比较其结果就知道是什么意思了。

yarsye 发表于 2010-6-4 09:25:41

实际运用中 怎么才会遇到?

3mile 发表于 2010-6-4 11:16:12

学习了。
不错的解释,基本明白了。
看来我的基础还是太差。

awingu 发表于 2010-6-4 11:21:43

学习了。
不错的解释,基本明白了。
看来我的基础还是太差

yarsye 发表于 2010-6-4 15:37:23

感谢楼上的解释

sxd 发表于 2010-6-5 00:38:50

总结关键词
二进制

skyer158 发表于 2010-6-6 11:22:46

多看看别人的作品,然后自己对照着学习啊,慢慢提高啊
页: [1] 2
查看完整版本: 白痴问个比较白痴的问题:在实际中我到底怎么样才会用到BitOR,BitAND,BitXOR?