找回密码
 加入
搜索
查看: 1916|回复: 2

[效率算法] [已解决]如何解开由1,2,4,8,16......组合起来的数

[复制链接]
发表于 2012-9-11 19:39:04 | 显示全部楼层 |阅读模式
本帖最后由 zch11230 于 2012-9-11 19:56 编辑

就比如像fileopen这条命令 提供了如下部分模式可选,当模式为9时 命令就知道是1+8
  0 = 只读模式(默认)
  1 = 写入模式(附加数据到文件尾部)
  2 = 写入模式(先删除之前的内容)
  8 = 如果目标目录不存在就创建(参考注意).

我想知道,我自己写一个多重条件判断,比如
Local $i=0
If FileExists("c:\windows") Then $i+=1
If FileExists("c:\abc") Then $i+=2
If FileExists("c:\1.txt") Then $i+=4
MsgBox(0,"test",$i)
现在我得到$i的值了,比如为5,我如何解开为1+4呢
发表于 2012-9-11 19:48:36 | 显示全部楼层

Local $i=5
If BitAND(0x00000001, $i) = 0x00000001 Then MsgBox(0, "", 1)
If BitAND(0x00000002, $i) = 0x00000002 Then MsgBox(0, "", 2)
If BitAND(0x00000004, $i) = 0x00000004 Then MsgBox(0, "", 4)
If BitAND(0x00000008, $i) = 0x00000008 Then MsgBox(0, "", 8)
If BitAND(0x00000010, $i) = 0x00000010 Then MsgBox(0, "", 16)
If BitAND(0x00000020, $i) = 0x00000020 Then MsgBox(0, "", 32)
If BitAND(0x00000040, $i) = 0x00000040 Then MsgBox(0, "", 64)
If BitAND(0x00000080, $i) = 0x00000080 Then MsgBox(0, "", 128)
 楼主| 发表于 2012-9-11 19:57:06 | 显示全部楼层
回复 2# veket_linux


    感谢解惑。。又多学习到一点。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-7 08:45 , Processed in 0.076335 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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