资源描述:
《vb程序中实现字节移位操作(byte shift operation in vb program)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、vb程序中实现字节移位操作(ByteshiftoperationinVBprogram)Author:LonelyNineSwordEmail:mikaiyue@sina.comDate:2001-7-519:37:15ByteshiftoperationinVBprogram(LiXiangjiang,2001,04,29,11:34)IntheuseofVBdataacquisitionsystemdevelopmentorindustrialcontrolsoftware,orlow-leveloperationso
2、nthefile,oftenrequiresabyteshiftoperation,buttheVBsystemdoesnotprovidebyteshiftoperationinstructionsandfunctions,providesonlyAnd(andOr),and(or)Xor(XOR)andEqu(orthesame),Not(non-)andseveralotherlogicoperations.TheauthorusedVBinthedevelopmentofindustrialcontrolsyste
3、msoftwareintheprocess,encounteredthisproblem,sotheuseofVBinthelogicaloperationinstruction,simulationassemblylanguagebyteshiftinstructionprogramsevenbyteshiftfunction:logicshiftleft,right,right,circularlogicarithmeticleftshift,rotateright,carrycycleleftshiftandrota
4、teright.Inassemblerlanguageinstructionfunction,logicshiftleftequivalentby2,logicshiftfunctionisequivalenttoonly2,usingthisfeatureintheVBprogramby2andinadditiontothe2methodstoachievetheleftandright,andthenAnd(andOr)and(or)logicoperations,judgmentifthereisashiftinth
5、eprocessofcarry,theflagisset.ProgramlistCFisacarryflag,whichusesBooleantypelogicalvariables.IfCFisTrue,thereisacarry,andFalsemeansnocarry.PublicCFAsBoolean'carryflag'1.logicmovesleftPublicFunctionSHL(OPRAsByte,nAsInteger)AsByteDimBDAsByteDimIAsIntegerBD=OPRForI=1,
6、To,N-1BD=(BDAnd&H7F)*2'movestheD7bittothelefttopreventbyteoverflowNextICF=BD,And,&H80'determineswhethertheD7bitiscarriedornotSHL=(BD,And,&H7F)*2EndFunction'2.logicalrightshiftPublicFunctionSHR(OPRAsByte,nAsInteger)AsByteDimBDAsByteDimIAsIntegerBD=OPRForI=1,To,N-1B
7、D=BD2'rightshiftNextICF=BD,And1'determineswhethertheD0bitiscarriedSHR=BD2EndFunction'3.arithmeticrightshiftPublicFunctionSAR(OPRAsByte,nAsInteger)AsByteDimBDAsByteDimIAsIntegerDimFg1AsByteBD=OPRFg1=BD,And,&H80ForI=1,To,N-1BD=BD2'rightshiftNextICF=BDAnd1'determi
8、neswhethertheD0bitiscarriedornotBD=BD2'rightshiftSAR=BD,Or,Fg1EndFunction'4.loopleftshiftPublicFunctionROL(OPRAsByte,nAsInteger)AsByteDimBDAsByteDimIAs