BitShift
执行移位运算.
BitShift ( value, shift )
参数
value
|
操作数的值.
|
shift
|
右移位数(负数则左移).
|
返回值
返回按请求位移后的值.
位操作均为 32 位整数.
备注
数字可以用十六进制表示法.
右移相当于减少一半; 左移则倍增.
函数示例
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Note: "b" is the symbol for byte.
; Assign a Local variable the bitwise left-shift operation of 2.
Local $iBitShift1 = BitShift(2, -1) ; 2 = 0010b left-shifted once -> 4 = 0100b
; Note: It is equivalent to do this: BitRotate(2, 1)
; Display the result.
MsgBox($MB_SYSTEMMODAL, "", $iBitShift1)
; Assign a Local variable the bitwise right-shift operation of 1.
Local $iBitShift2 = BitShift(1, 1) ; 1 = 0001b right-shifted once -> 0 = 0000b
; Display the result.
MsgBox($MB_SYSTEMMODAL, "", $iBitShift2)
; Assign a Local variable the bitwise left-shift operation of 14.
Local $iBitShift3 = BitShift(14, -2) ; 14 = 1110b left-shifted twice -> 56 = 0011 1000b
; Display the result.
MsgBox($MB_SYSTEMMODAL, "", $iBitShift3)
; Assign a Local variable the bitwise
Local $iBitShift4 = BitShift(1, -31)
;1 = 0001b right-shifted 31 times -> -2147483648 (32 bits) = 1000 0000 0000 0000 0000 0000 0000 0000b
;Note: in 2's-complement notation, the 32nd digit from the right has a negative sign.
; Display the result.
MsgBox($MB_SYSTEMMODAL, "", $iBitShift4)
EndFunc ;==>Example
----------------------------------------
该函数可以通过命令 exect 调用
参见:
BitAND, BitNOT, BitOR, BitXOR, Hex, BitRotate
;; 返回3,因为14与双右移被转换为3
;; 14以二进制形式0000000000000000000000001110
;; 3以二进制形式0000000000000000000000000011
BitShift(14,-2)
;; 返回56,因为14的左移左转换为56
;; 14以二进制形式0000000000000000000000001110
;; 56以二进制形式00000000000000000000000000011000
BitShift(1,-31)
;; 返回-2147483648,因为这是表示负数的第二种方式(数字被反转)
;; 从右边的第32位数字是一个负号。
;; 1以二进制形式00000000000000000000000000000001
;;-2147483648二进制形式为10000000000000000000000000000000000
exect=BitShift(14,2) GLOBALEXECT<a> ;; 执行按位移位操作。 (返回3)
© Аверин Андрей для Total Commander Image Averin-And@yandex.ru
|