找回密码
 加入
搜索
查看: 8847|回复: 24

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

 火... [复制链接]
发表于 2010-6-1 09:31:50 | 显示全部楼层 |阅读模式
我看了help file只是了解他们是按位“或”“与”运算,但是在实际中我到底怎么样才会用到呢?
发表于 2010-6-1 10:00:21 | 显示全部楼层
想要知道,想要提高,还是建议LZ多看看源码作品,自己再动手写作品。
 楼主| 发表于 2010-6-1 10:08:26 | 显示全部楼层
我也想这样的啊 但是我每次写 都是我已经会的 不会的学的有点慢
发表于 2010-6-1 10:12:43 | 显示全部楼层
最主要的功能是简化语句
发表于 2010-6-1 10:22:34 | 显示全部楼层
google下"位与","位或"的概念

评分

参与人数 1金钱 +15 收起 理由
afan + 15

查看全部评分

发表于 2010-6-2 14:28:57 | 显示全部楼层
属性集合 和 权限相关 的时候基本要用到

不过还是先顶一下楼上的蛋蛋
发表于 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)

评分

参与人数 1金钱 +10 收起 理由
李岸 + 10 我觉得你才是这篇帖子中对这个问题理解最透 ...

查看全部评分

 楼主| 发表于 2010-6-3 17:00:14 | 显示全部楼层
有点晕 没用过
发表于 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进制,每位相对应,再比较其结果就知道是什么意思了。

评分

参与人数 1金钱 +30 收起 理由
水木子 + 30 受教啦!

查看全部评分

 楼主| 发表于 2010-6-4 09:25:41 | 显示全部楼层
实际运用中 怎么才会遇到?
发表于 2010-6-4 11:16:12 | 显示全部楼层
学习了。
不错的解释,基本明白了。
看来我的基础还是太差。
发表于 2010-6-4 11:21:43 | 显示全部楼层
学习了。
不错的解释,基本明白了。
看来我的基础还是太差
 楼主| 发表于 2010-6-4 15:37:23 | 显示全部楼层
感谢楼上的解释
发表于 2010-6-5 00:38:50 | 显示全部楼层
总结关键词
二进制
发表于 2010-6-6 11:22:46 | 显示全部楼层
多看看别人的作品,然后自己对照着学习啊,慢慢提高啊
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-28 18:54 , Processed in 0.102076 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表