BitRotate
执行旋转移位运算.
BitRotate ( value [, shift = 1 [, size = "W"]] )
参数
value
|
操作数的值.
|
shift
|
[可选] 左旋转位数 (负值右旋转). 如不指定, 默认为 1.
|
size
|
[可选] 决定旋转大小的字串, 默认为 (16 位). 见下文.
|
Size 参数 :
"B"
|
旋转位的低位字节(8 位).
|
"W"
|
旋转位的低位字(16 位).
|
"D"
|
旋转位的整个双字(32 位).
|
返回值
成功:
|
返回旋转所需要的位值.
|
失败:
|
设置 @error 为非 0 值, 表示"size"参数值无效.
|
备注
数字可以用十六进制表示法.
函数示例
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Note: "b" is the symbol for byte.
; Assign a Local variable the bitwise left-rotate operation of 2.
Local $iBitRotate1 = BitRotate(2, 1) ; 2 = 0010b left-rotated once -> 4 = 0100b
; Note: It is equivalent to do this: BitShift(2, -1)
; Display the result.
MsgBox($MB_SYSTEMMODAL, "", $iBitRotate1)
; Assign a Local variable the bitwise right-rotate operation of 1.
Local $iBitRotate2 = BitRotate(1, -1) ; 1 = 0001b right-rotated once -> 32768 (32 bits) = 1000 0000 0000 0000b
; Display the result.
MsgBox($MB_SYSTEMMODAL, "", $iBitRotate2)
; Assign a Local variable the bitwise right-rotate operation of 14.
Local $iBitRotate3 = BitRotate(14, -2) ; 14 = 1110b right-rotated twice -> 32771 (16 bits) = 1000 0000 0000 0011b
; Display the result.
MsgBox($MB_SYSTEMMODAL, "", $iBitRotate3)
; Assign a Local variable the bitwise right-rotate operation of 14 on 32 bits.
Local $iBitRotate4 = BitRotate(14, -2, "D")
; 14 = 1110b right-rotated twice -> -2147483645 (32 bits) = 1000 0000 0000 0000 0000 0000 0000 0011b (the first bit is signed)
; Display the result.
MsgBox($MB_SYSTEMMODAL, "", $iBitRotate4)
EndFunc ;==>Example
----------------------------------------
该函数可以通过命令 exect 调用
参见:
BitShift, BitAND, BitNOT, BitOR, BitXOR, Hex
; 旋转 - 圆圈移动,所有位向右移动,最后移动到开头,反之亦然.
BitRotate(7,2)
; 返回28,因为具有双旋的7被转换为28
; 7以二进制形式0000000000000111
; 28以二进制形式0000000000011100
BitRotate(14,-2)
; 返回32771,因为在16位内向右旋转的14个转换为32771
; 14以二进制形式0000000000001110
; 32771二进制形式1000000000000011
BitRotate(14,-2,'D')
; 返回-2147483645因为在32位宽度内向右旋转的14个转换为-2147483645
; 14以二进制形式0000000000000000000000001110
; -2147483645,二进制形式为1000000000000000000000000011
exect=BitRotate(7,2) GLOBALEXECT<a> ;; 执行循环逐位移动操作。 (返回28)
© Аверин Андрей для Total Commander Image Averin-And@yandex.ru
|