[VB6]bit-shift operation
VB6/VBA不支援 "<<" & ">>"的位元操作
(C/C++/C#)
a = b << n ;b左移n bits
a = b >> n ;b右移n bits
(VB/VBA)
a = b * (2 ^ n) '左移, 乘以2的n次方
a = b / (2^ n) '右移, 除以2的n次方
Demo code
Result
(C/C++/C#)
a = b << n ;b左移n bits
a = b >> n ;b右移n bits
(VB/VBA)
a = b * (2 ^ n) '左移, 乘以2的n次方
a = b / (2^ n) '右移, 除以2的n次方
Demo code
Option Explicit Sub bit_shift() Dim reg As Byte reg = &H1 ' 1 Debug.Print "Before: 0x" & Hex(reg) ' 2 reg = reg * (2 ^ 5) Debug.Print "left-shift 5-bits: 0x" & Hex(reg) ' 3 reg = reg / (2 ^ 2) Debug.Print "right-shift 2-bits: 0x" & Hex(reg) End Sub
Result
留言
張貼留言