注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
a26409310的个人空间 https://home.eeworld.com.cn/space-uid-263238.html [收藏] [复制] [分享] [RSS]
日志

vb计算crc form8 十六进制 浮点 转换

已有 593 次阅读2010-4-12 18:27

'form1--form8,8个窗体,一个模块

’form8

Option Explicit

Private Type A_Single

aa As Single

End Type

Private Type A_Byte

bb(0 To

3)

As Byte

End Type

Dim

Da

As A_Single

Dim

By

As A_Byte

Private Function Str2Float(str As String) As

Double

Dim

k

As Integer

Dim

i

As Integer

Dim

j

As Integer

Dim

s

As Integer

Dim

SS

As Integer

Dim

E

As Integer

Dim

M

As Long

Dim

d

As Double

Dim

n

As Integer

Dim

h

As Integer

Dim

l

As Integer

Dim

s2()

As String,

st

As String

s2 = Split(str, " ")

If UBound(s2) <> 3 Then

MsgBox "数据格式错误,无法转换!"

Str2Float = 0

Exit Function

End If

For i = 0 To UBound(s2)

If Len(s2(i)) = 1 Then s2(i) = "0" & s2(i)

st = st & s2(i)

Next i

Dim

buff(7)

As Byte

For i = 0 To 7

buff(i) = Asc(Mid(st, i + 1, 1))

Next i

Dim

a(15)

As Byte

For i = 0 To 15

a(i) = i

Next i

Dim

b(7)

As Byte

For j = 0 To 7

If buff(j) >= 48 And buff(j) <= 57

Then

k = buff(j) - 48

b(j) = a(k)

ElseIf buff(j) >= 65 And buff(j) <=

70 Then

k = buff(j) - 65

b(j) = a(k + 10)

Else

Exit Function

End If

Next j

Dim

c(3)

As Long

For n = 0 To 6 Step 2

c(n / 2) = ((b(n) And &H7F) * (2 ^ 4)) Or (b(n + 1)

And &H7F)

Next n

s = c(0) \ 2 ^ 7

If s = 1 Then

SS = -1

Else

SS = 1

End If

E = ((c(0) And &H7F) * 2) Or ((c(1) And

&H80) \ 2 ^ 7)

M = ((c(1) And &HFFFFFF) * 2 ^ 16 And

&H7FFFFF) Or ((c(2) And &HFFFFFF) *

2 ^ 8) Or ((c(3) And &HFFFFFF))

d = SS * 2 ^ (E - 127) * (M / (2 ^ 23) + 1)

Str2Float = d

End Function

'Private Sub Command1_Click()

'Debug.Print Str2Float("A

D7

A3 3C")

'Text1.Text = Str2Float("A

D7

A3 3C")

'End Sub

Private Sub Command1_Click()

If Text1.Text = "" Or Text2.Text = "" Or

Text3.Text = "" Or Text4.Text = "" Then

Exit Sub

End If

Text5.Text = ""

By.bb(0) = "&h"

& Text1.Text

By.bb(1) = "&h"

& Text2.Text

By.bb(2) = "&h"

& Text3.Text

By.bb(3) = "&h"

& Text4.Text

LSet Da = By

Text5.Text = Da.aa

End Sub

Private Sub Command2_Click()

Dim Arry_Out(0 To

3)

As Byte

If Not IsNumeric(Text5.Text) Then Exit Sub

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Text4.Text = ""

Da.aa = Text5.Text

LSet By = Da

Arry_Out(0) = By.bb(0)

Arry_Out(1) = By.bb(1)

Arry_Out(2) = By.bb(2)

Arry_Out(3) = By.bb(3)

Text1.Text = Hex(Arry_Out(0))

Text2.Text = Hex(Arry_Out(1))

Text3.Text = Hex(Arry_Out(2))

Text4.Text = Hex(Arry_Out(3))

End Sub

Private Sub Command3_Click()

Unload Me

Form1.Show

End Sub

Private Sub Command4_Click()

End

End Sub

Private Sub Form_Load()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Text4.Text = ""

Text5.Text = ""

End Sub

分享

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章