⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convnums.txt

📁 RK4000通讯协议.
💻 TXT
字号:
* Hexadecimal to Decimal: [Henri at] hleboeuf@generation.net

Sub Form_Load ()

	Dim x As String
	Dim y As Variant

	x = "fffe"
	y = CLng("&H" & x)

	If y < 0 Then y = y + 65536    ' returns 65534
	
	MsgBox y

End Sub


* Converting a string to an integer: Cal Stover

Dim SomeVariable as Integer
SomeVariable = CInt(Label2.Caption) + 100

Dim SomeVariable as Single
SomeVariable = CSng(Val(Label2.Caption) + 100)


* convert a number in Hexadecimal to Binary -chris

A very fast conversion from hex to binary can be done with a sixteen
element look-up table - a single hex digit converts to four binary
digits.  So:

Function Hex2Bin$(HexValue$)
  CONST BinTbl ="0000000100100011010001010110011110001001101010111100110111101111"
  Dim X, Work$
  Work$ = ""
  For X = 1 to Len(HexValue$)
    Work$ = Work$ + Mid$(BinTbl, (Val("&h" + Mid$(HexValue$, X, 1) - 1) * 4 + 1, 4)
  Next
  Hex2Bin$ = Work$
End Function

You could also code BinTbl as an array which would eliminate one of the
Mid$() calls, but then the array would either have to be built ahead of
time or built every time you called the Hex2Bin function.  You could try
all three options and see which is faster.


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -