布尔代数是编程的必修课之一.
下面拿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)
|