?? 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 + -