《VB中位操作运算函数.docx.pdf》由会员分享,可在线阅读,更多相关《VB中位操作运算函数.docx.pdf(24页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、VB中位操作运算函数VB function (shift instruction)the Module: BitPlus BasCode By Hermit smth, Jun. 1st, 2000Email: mailtocwsohu. comMay these functions will help you, and? Please keep this header if you use my code, thanks!provides a function of bit-operation in VBthe SHL logic moves the SHR logic to the rig
2、htSAL arithmetic left SAR srithmetic rightthe ROL loop left the ROR loop to the rightRCL carries the carry loop to the left and the RCR carry circulates tothe rightBin translates the given data into a 2-point stringusageSHR SHR SAL SAR ROL ROR is basically the same, as an exampleof SHLyou cdn shift
3、the variable type, Byte (Byte), Integer (Integer), LongInteger (Long)return value True is shifted successfully,False shift fails,and Falseis returned when the non-afore-mentioned type is shifted,zNum passes reference variable, which is shifted, and the programoverwrites the value of Num to the resul
4、t of the operationTheiCL value variable, the number of times shifted,the default valueis shifted one timeExample Dim A As IntegerA二&hlOif SHL A is shifted, A二 &H20like SHL A, 2 shiftedlike SHL A, 4 shiftedRCR is similar to RCL, as an example of RCLthere is a need for a given parameter, the in put va
5、lue of the first shift,iCFBin, for example,A二 &IIIIf A is byte, Bin (A) returns the value as 00000001If A is an integer, Bin (A) returns the value asooooooooooooooor,If A is A long integer, then Bin (A) returns the valueasooooooooooooooooooooooooooooooooooor,If the incoming parameter is not of the a
6、bove type, the return valueisFor more information, please refer to the relevant assembly bookslogical leftThe Public Function SHL (ByRef Num As Variant, Optional ByVai iCL As Byte二1) AsBooleanDim I As ByteDim bMask As Byte, iMask As Integer, IMask As LongThe Select Case VarType (Num)Case 2 16 bitsFo
7、r I = 1 To iCLIMask二0If (Num And & H4000) , Then iMask二&h8000Num二(Num)NextCase 3 32 bitsFor I二1 To iCLLMask二0If (Num And/H40000000) , Then IMask二&h80000000Num二(Num)Next8 bits Case 17 For I二1 To iCLBMask二0If (Num And & H40) , Then bMask二&h80Num二(Num)NextCase the ElseSHL二FalseThe Exit FunctionEnd the
8、SelectSHL二TrueEnd the Functionlogic moves to the rightThe Public Function SHR (ByRef Num As Variant, Optional二1) AsBooleanDim I As ByteDim bMask As Byte, iMask As Integer, IMask As LongThe Select Case VarType (Num)Case 2 16 bitsFor I = 1 To iCLIMask二0ByVaiAs ByteiCLIf (Num And & H8000) , Then iMask二
9、&h4000Num二(Num)NextCase 3 32 bitsFor I二1 To iCLLMask二0If (Num And &h80000000) , Then IMask二Num二(Num And & h7fffff) 2 Or IMaskNext8 bits Case 17 For I = 1 To iCLBMask二0如果(Num和&H80)小于0,那么b掩码二&H40Num二(Num和&f) 2或b掩码下一 其他情况下&h40000000月二False退岀函数最终选择月二True结束函数“算术左移公共函数SAL(ByRef Num作为变量,可选的ByVai iCL作为字节二尔萨
10、尔二SHL (Num iCL)结束函数“算术右移公共函数SAR(ByRef Num作为变量,可选的ByVai iCL作为字节二尔 昏暗的我作为字节将模糊的b掩码作为字节,以整数的形式表示,1掩码选择案例VarType (Num))布)布11例2的16位i二1到iCLiMask二0如果(Num和&H8000)小于0,那么iMask=&HC000Num二(Num And&fff)2或iMask下一3 32位i二1到iCL如果(Num和H80000000)小于0,那么1面罩=&HC0000000Num= (Num和&fffffff)2或1面膜下一例17的8位如果(Num和&H80)小于0,那么b掩码
11、二&IIC0Num二(Num和&f) 2或b掩码下一其他情况下SAR = False退岀函数最终选择SAR = True结束函数“循环左移公共函数罗尔(ByRef Num作为变量,可选的ByVai iCL作为字节二1)布尔昏暗的我作为字节将模糊的b掩码作为字节,以整数的形式表示,1掩码选择案例VarType (Num)例2的16位13T底【二!8切ZI询削型T迤Z(剧肘肘亞H孔坐山/)二ninNl=W T 7雎0壬W (00000008H吐叫)泮W00000008H加富厦I乡雎0壬/(0000000闭 吐 叫)番皿bMask如果(如果(二0Num和&H40)Num和&H80)0二怦IH13 T
12、匾T=T_丄乍测!塗乙(刖丸H典叫)二uinNH躺乍测!胡sew!乡雎 p 壬申(0008H劄吐叫)番皿0008H器乍即!“0壬/(000闭牝*山叫)番皿0二怦叽!T)!底1=1小于0,那么b掩码二&H80小于0,则b掩码二b掩码或&H1Num二(Num和H3F) 2或b掩码下一其他情况下高校二False退岀函数最终选择高校二True结束函数“循环右移公共函数R0R(ByRef Num作为变量,可选的ByVai iCL作为字节二1)布尔昏暗的我作为字节 将模糊的b掩码作为字节,以整数的形式表示,1掩码选择案例VarType (Num)例2的16位i二1到iCLiMask二0如果(Num和&H8
13、000)小于0,那么iMask=&H4000如果(Num和Hl)小于0,那么iMask二iMask或H8000Num二(Num And&fff)2或iMask下一3 32位i二1到iCLIMask二0如果(Num和H80000000)小于0,那么1面罩二&H40000000如果(Num和H1)小于0,那么1口罩二1口罩或H80000000Num= (Num和&fffffff)2或1面膜 下一例17的8位i二1到iCLbMask二0如果(Num和&H80)小于0,那么b掩码二&H40如果(Num和Hl)小于0,则b掩码二b掩码或&H80Num二(Num和&f) 2或b掩码下一其他情况下R0R =
14、 False退岀函数最终选择R0R = True结束函数“带进位循环左移公共函数RCL(ByRef Num As变量,可选ByVai iCL作为字节二字节二0)作为布尔值使我成为字节,CF为字节将模糊的b掩码作为字节,以整数的形式表示,1掩码CF iCf二1, Op选择案例VarType (Num)例2的16位i二1到iCL如果CF二0iMask二0其他的iMask二1如果如果(Num和&H4000)小于0,那么如果(Num和&H8000)小于0CF二1其他的二或H8000iMaskiMask0H0TH蘸E:ooo00壬/(08H孔*山/)帝皿08恥迤咸瞬q二忸瞬q flM 0屮(0闭马如果N
15、um二(Num和下一其他情况下RCL = False退岀函数H3F) 2或b掩码吐N)番皿I二怦IW関珂當0 =乍可2 0番皿四8切ZT阍 _丄Wffl T塗乙(刖肘剧品H马咄山nN)二山nN13 T K 1=1最终选择RCL = True结束函数“带进位循环右移公共函数RCR(ByRef Nuni作为变量,可选的ByVai iCL作为字节二Op字节=0)作为布尔值使我成为字节,CF为字节将模糊的b掩码作为字节,以整数的形式表示,1掩码CF iCf选择案例VarType (Num)例2的16位i二1到iCL如果CF二1iMask二&H80001,其他的iMask二0如果如果(Num和&H800
16、0)小于0,那么iMask二iMask或&H4000如果(Num和H1)小于0CF二1其他的CF二0如果Num二(Num And&fff)2或下_i二1到iCL如果CF二1IMask二&H80000000其他的iMaskIMask二0如果如果(Num和H80000000)小于0,那么1口罩二1口罩或&H40000000如果(Num和H1)小于0CF二1其他的CF二0如果Num= (Num和&fffffff)2例17的8位i二1到iCL如果CF二1bMask二&H80其他的bMask二0或1面膜 下一如果如果(Num和&H80)小于0,则b掩码二b掩码或&H40如果(Num和H1)小于0CF二1
17、其他的CF二0如果Num二(Num和&f) 2或b掩码下一软二False退岀函数最终选择软二True结束函数“将数值转化为二进制字符串公共函数Bin(ByVal Num作为变量)作为字符串昏暗的tmpStr作为字符串昏暗的iMask一样长暗iCf作为字节,iMax为字节选择案例VarType (Num)情形2: iMax二15整数16位情形3:iMax=31的长32位案例17:iMax二7字节8位本二 退出函数最终选择iMask二1如果iMask和NumtmpStr二 1其他的tmpStr二0如果对于iCf二1到iMax如果iCf二31如果Num大于0 tmpSti-/zO,z+tmpStr其他的如果退出 如果iMask=iMask 2如果iMask和Num tmpSti-r+tmpStr其他的tmpSti-O+tmpStr/zrz+tmpStrtmpSti-如果下一本二tmpStr结束函数