VB 负数移位 急急急……

lt114896 2012-04-26 11:32:10
求解VB负数移位怎么移,本人初学,用到VB的移位,不知道负数怎么以为,求指导,最好有源代码! 急急急……
...全文
187 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
laviewpbt 2012-04-27
  • 打赏
  • 举报
回复
Private Type LARGEINT
Long1 As Long
Long2 As Long
End Type

Private Declare Function RLIShiftLeft Lib "ntdll" Alias "RtlLargeIntegerShiftLeft" (ByVal Val1 As Long, ByVal Val2 As Long, ByVal ShiftCount As Long) As LARGEINT

Private Declare Function RLIShiftRight Lib "ntdll" Alias "RtlLargeIntegerShiftRight" (ByVal Val1 As Long, ByVal Val2 As Long, ByVal ShiftCount As Long) As LARGEINT


Tiger_Zhao 2012-04-27
  • 打赏
  • 举报
回复
http://www.excely.com/excel-vba/bit-shifting-function.shtml
类似C++中的 <<>>
熊孩子开学喽 2012-04-26
  • 打赏
  • 举报
回复
是连同符号位一起移呢,还是不带符号位移动呢
网络菜鸟00 2012-04-26
  • 打赏
  • 举报
回复
你的移位是如何定义的?
左移?右移?
给个BAS,不知是否满足你的需求:
Option Explicit
Private Const BinTbl = "0000;0001;0010;0011;0100;0101;0110;0111;1000;1001;1010;1011;1100;1101;1110;1111;"
Private Const HexTbl = "0123456789ABCDEF"

Function MoveRight$(ByVal BaseNum&, MoveNum&) '右移
Dim BaseStr$, Result$
BaseStr = Oct2Bin(BaseNum)
Debug.Print BaseStr
MoveRight = Left(String(MoveNum, "0") & BaseStr, Len(BaseStr))
MoveRight = Bin2Oct(MoveRight)
End Function

Function MoveLeft$(ByVal BaseNum&, MoveNum&) '左移
Dim BaseStr$, Result$
BaseStr = Oct2Bin(BaseNum)
MoveLeft = Right(BaseStr & String(MoveNum, "0"), Len(BaseStr))
MoveLeft = Bin2Oct(MoveLeft)
End Function

Function Oct2Bin$(ByVal Value&)
Dim i&, HexValue$
Const BinTbl = "0000000100100011010001010110011110001001101010111100110111101111"
HexValue = CStr(Hex$(Value))
For i = 1 To Len(HexValue)
Oct2Bin = Oct2Bin + Mid(BinTbl, Val("&H" + Mid(HexValue, i, 1)) * 4 + 1, 4)
Next i
End Function

Function Bin2Oct$(ByVal BinValue$)
Dim s As String * 4
Dim i&
If Len(BinValue) Mod 4 <> 0 Then
BinValue = String(4 - Len(BinValue) Mod 4, "0") + BinValue
End If
For i = 1 To Len(BinValue) Step 4
s = Mid(BinValue, i, 4) & ";"
Bin2Oct = Bin2Oct + Mid(HexTbl, (InStr(BinTbl, s) - 1) / 5 + 1, 1)
Next
Bin2Oct = Val("&H" & Bin2Oct)
End Function
'示例
Private Sub Command1_Click()
Debug.Print MoveRight(-123456, 2) '右移2位
End Sub

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧