📄 vb17.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0057)http://www.pconline.com.cn/experience/subject/VB/vb17.htm -->
<HTML><HEAD><TITLE>|><| 太平洋电脑信息网</TITLE><!-- #BeginTemplate "/Templates/0723.dwt" --><!-- #BeginEditable "doctitle" --><!-- #EndEditable -->
<META content="text/html; charset=gb2312" http-equiv=Content-Type><LINK
href="vb17.files/text.css" rel=stylesheet>
<STYLE type=text/css>.sfont {
LINE-HEIGHT: 18pt
}
</STYLE>
<META content="MSHTML 5.00.2014.210" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD vAlign=top width="100%">
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR bgColor=#303880>
<TD><A href="http://www.pconline.com.cn/"><IMG alt=太平洋电脑信息网 border=0
height=18 hspace=30 src="vb17.files/txtpconline.gif"
width=96></A><IMG height=10 src="vb17.files/blank.gif"
width=400></TD></TR></TBODY></TABLE></TD>
<TD align=right background=vb17.files/bw.gif noWrap width=130><IMG
height=26 src="vb17.files/bw.gif" width=10><A
href="http://www.pconline.com.cn/sitemap/"><IMG alt=网站地图 border=0
height=26 src="vb17.files/sitemap.gif" width=21></A><IMG height=26
src="vb17.files/bw.gif" width=10><A
href="http://www.pconline.com.cn/tpy/"><IMG alt=关于太平洋 border=0 height=26
src="vb17.files/aboutus.gif" width=21></A><IMG height=26
src="vb17.files/bw.gif" width=10><A
href="http://www.pconline.com.cn/tpy/tariff.html"><IMG alt=与我们联系 border=0
height=26 src="vb17.files/contact.gif" width=21></A><IMG height=26
src="vb17.files/bw.gif" width=10></TD></TR></TBODY></TABLE><BR>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=760>
<TBODY>
<TR>
<TD bgColor=#666666><IMG height=1 src="vb17.files/blank.gif" width=1></TD>
<TD bgColor=#666666><IMG height=1 src="vb17.files/blank.gif" width=1></TD>
<TD> </TD>
<TD colSpan=2 noWrap><A
href="http://www.pconline.com.cn/experience/index.html"><IMG
align=absBottom alt=企业之窗 border=0 height=15
src="vb17.files/txtexperience.gif" width=68></A> <A
href="http://www.pconline.com.cn/">首 页</A> <A
href="http://www.pconline.com.cn/market/">今日报价</A> <A
href="http://www.pconline.com.cn/recommend/">产品推介</A> <A
href="http://www.pconline.com.cn/yp/">企业之窗</A> <A
href="http://www.pconline.com.cn/news/">科技新闻</A> <A
href="http://www.pconline.com.cn/product/">产品查询</A> <A
href="http://www.pconline.com.cn/download/">软件下载</A></TD></TR>
<TR>
<TD><IMG height=1 src="vb17.files/blank.gif" width=1></TD>
<TD><IMG height=1 src="vb17.files/blank.gif" width=1></TD>
<TD><IMG height=1 src="vb17.files/blank.gif" width=21></TD>
<TD bgColor=#ffa000 colSpan=2><IMG height=1 src="vb17.files/blank.gif"
width=1></TD></TR>
<TR>
<TD bgColor=#666666><IMG height=1 src="vb17.files/blank.gif" width=1></TD>
<TD bgColor=#cdcdcd><IMG height=5 src="vb17.files/blank.gif" width=1></TD>
<TD align=right colSpan=3><IMG height=6 src="vb17.files/ffa000.gif"
width=1></TD></TR>
<TR>
<TD bgColor=#666666><IMG height=1 src="vb17.files/blank.gif" width=1></TD>
<TD align=right><A href="http://www.pconline.com.cn/"><IMG alt=太平洋电脑信息网
border=0 height=35 src="vb17.files/pconline.com.cn.gif" vspace=10
width=162></A></TD>
<TD> </TD>
<TD vAlign=bottom><!-- #BeginEditable "important_news" --><IMG height=40
src="vb17.files/blank.gif" width=350><!-- #EndEditable --></TD>
<TD align=right vAlign=top><!-- #BeginEditable "adv_top" --><IMG alt=广告位
height=43 src="vb17.files/icon.gif"
width=190><!-- #EndEditable --></TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=760>
<TBODY>
<TR>
<TD bgColor=#666666 width=1><IMG height=1 src="vb17.files/blank.gif"
width=1></TD>
<TD vAlign=top width=170><!-- #BeginEditable "addons" --><!--替代为附加信息 --><!-- #EndEditable --></TD>
<TD bgColor=#666666 width=1><IMG height=1 src="vb17.files/blank.gif"
width=1></TD>
<TD><IMG height=1 src="vb17.files/blank.gif" width=21></TD>
<TD colSpan=3 vAlign=top width=566><!-- #BeginEditable "1" --><IMG
height=1 src="vb17.files/blank.gif" width=566><BR><IMG height=1
src="vb17.files/666666.gif" width=420><BR><IMG height=13
src="vb17.files/blank.gif" width=1><A
href="http://www.pconline.com.cn/experience/">经验共享</A> > <SPAN
class=greenb><A
href="http://www.pconline.com.cn/experience/subject/VB/index.html">专题教程</A></SPAN><A
href="http://www.pconline.com.cn/experience/subject/VB/index.html">
VB专区</A>> <BR><IMG height=1 src="vb17.files/666666.gif" vspace=1
width=420><BR>
<P align=center><B><FONT color=#000066><SPAN
class=sfont>用VB进行移位操作</SPAN></FONT></B></P>
<P align=left><SPAN
class=sfont>VB没有提供移位操作的指令和函数,只提供and(与)、or(或)、xor(异或)、eqv(同或)、not(非)等几个运算符,<BR>而编程时有时需要对一个字节进行移位操作(如进行加密),怎么办?其实只用and、or二个运算符即可搞掂。<BR>例如要将变量byte1的第八位置1(假设byte1的二进制值为01001101),则只需byte1
or &h80 (即01001101 or 10000000),<BR>如要将第八位置0,则只需byte1 and
&h7f。请看下面程序段是如何实现循环左移的:<BR><BR>Public Function byteleft(byte1 As Byte,
n As Integer) As Byte '将byte1左移n位<BR>Dim intem As Byte '临时变量<BR>Dim intem1
As Byte '临时变量<BR>Dim x, y As Integer<BR>intem1 = byte1<BR>For x = 1 To n
'移多少位就循环多少次<BR>For y = 8 To 1 Step -1 '从第八位(左边第一位)开始循环左移<BR>Select Case
y<BR>Case 8<BR>If (intem1 And &H80) = &H80 Then
'如果临时变量intem1的第八位是1,<BR>intem = &H1 '则将临时变量intem置1,<BR>Else<BR>intem =
&H0 '反之置0<BR>End If<BR>Case 7<BR>If (intem1 And &H40) = &H40
Then '如果临时变量intem1的第七位是1,<BR>intem1 = intem1 Or &H80
'则将其第八位置1(其它位不变),<BR>Else<BR>intem1 = intem1 And &H7F
'反之将第八位置0(其它位不变)<BR>End If<BR>Case 6<BR>If (intem1 And &H20) =
&H20 Then '操作与上面相同<BR>intem1 = intem1 Or &H40<BR>Else<BR>intem1 =
intem1 And &HBF<BR>End If<BR>Case 5<BR>If (intem1 And &H10) =
&H10 Then<BR>intem1 = intem1 Or &H20<BR>Else<BR>intem1 = intem1
And &HDF<BR>End If<BR>Case 4<BR>If (intem1 And &H8) = &H8
Then<BR>intem1 = intem1 Or &H10<BR>Else<BR>intem1 = intem1 And
&HEF<BR>End If<BR>Case 3<BR>If (intem1 And &H4) = &H4
Then<BR>intem1 = intem1 Or &H8<BR>Else<BR>intem1 = intem1 And
&HF7<BR>End If<BR>Case 2<BR>If (intem1 And &H2) = &H2
Then<BR>intem1 = intem1 Or &H4<BR>Else<BR>intem1 = intem1 And
&HFB<BR>End If<BR>Case 1<BR>If (intem1 And &H1) = &H1
Then<BR>intem1 = intem1 Or &H2<BR>Else<BR>intem1 = intem1 And
&HFD<BR>End If<BR>If intem = &H1 Then
'移完第一位后,如果intem是1(即第八位是1)<BR>intem1 = intem1 Or &H1
'则将intem1的第一位置1<BR>Else<BR>intem1 = intem1 And &HFE '反之置0<BR>End
If<BR>End Select<BR>Next y<BR>Next x<BR>byteleft = intem1
'将intem1的值返回给函数名<BR>End Function<BR>参照此程序段,不难实现循环右移。<BR>(此程序段在VB5上调试通过。)
</SPAN>
<P align=right><A
href="http://www.pconline.com.cn/experience/subject/VB/index.html">----更多的文章</A>
<!-- #EndEditable --></P></TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=760>
<TBODY>
<TR>
<TD bgColor=#666666 width=1><IMG height=1 src="vb17.files/blank.gif"
width=1></TD>
<TD align=right vAlign=bottom width=170><IMG height=10
src="vb17.files/blank.gif" width=170><BR></TD>
<TD bgColor=#666666 width=1><IMG height=1 src="vb17.files/blank.gif"
width=1></TD>
<TD width=21><IMG height=1 src="vb17.files/blank.gif" width=21></TD>
<TD bgColor=#eeeeee width=566><IMG height=10 src="vb17.files/blank.gif"
width=566><BR>版权所有©1999 太平洋电脑信息网<BR><FONT
face="Arial, Helvetica, sans-serif"><A
href="mailto:exp@pconline.com.cn">exp@pconline.com.cn</A></FONT> <IMG
height=1 src="vb17.files/hhvisit.html" width=1> </TD></TR></TBODY></TABLE><!-- #EndTemplate --></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -