Declare Sub hmemcpy Lib "kernel" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Function CVI (X As String) As Integer
 If Len(X) <> 2 Then
  MsgBox "Illegal Function Call"
  Stop
 End If
 hmemcpy temp%, ByVal X, 2
 CVI = temp%
End Function

Function CVL (X As String) As Long
 If Len(X) <> 4 Then
  MsgBox "Illegal Function Call"
  Stop
 End If
 hmemcpy temp&, ByVal X, 4
 CVL = temp&
End Function

Function CVS (X As String) As Single
 If Len(X) <> 4 Then
  MsgBox "Illegal Function Call"
  Stop
 End If
 hmemcpy temp!, ByVal X, 4
 CVS = temp!
End Function

Function CVD (X As String) As Double
 If Len(X) <> 8 Then
  MsgBox "Illegal Function Call"
  Stop
 End If
 hmemcpy temp#, ByVal X, 8
 CVD = temp#
End Function

Function CVSMBF (OldStringSP As String) As Single
 Dim X, Sign, Exponent As Integer
 Dim NewNum As String
 Static ONA(0 To 3), NNA(0 To 7)
 For X = 0 To 3
  ONA(X) = Asc(Mid$(OldStringSP, X + 1, 1))
 Next
 For X = 0 To 7
  NNA(X) = 0
 Next
 Sign = ONA(2) And 128
 Exponent = ONA(3) - 129 + 1023
 NNA(6) = Exponent * 2 ^ 4 And 255
 NNA(7) = (Exponent \ 2 ^ 4 And 255) Or Sign
 For X = 2 To 1 Step -1
  ONA(X) = ONA(X) * 2 ^ 1 And 255
  ONA(X) = ONA(X) Or ONA(X - 1) \ 2 ^ 7 And 255
 Next
 ONA(0) = ONA(0) * 2 ^ 1 And 255
 For X = 6 To 4 Step -1
  NNA(X) = NNA(X) Or ONA(X - 4) \ 2 ^ 4 And 255
  NNA(X - 1) = ONA(X - 4) * 2 ^ 4 And 255
 Next
 For X = 0 To 7
  NewNum = NewNum + Chr$(NNA(X))
 Next
 CVSMBF = CSng(CVD(NewNum))
End Function

Function CVDMBF (OldStringDP As String) As Double
 Dim X, Sign, Exponent As Integer
 Dim NewNum As String
 Static ONA(0 To 7), NNA(0 To 7)
 For X = 0 To 7
  ONA(X) = Asc(Mid$(OldStringDP, X + 1, 1)): NNA(X) = 0
 Next
 Sign = ONA(6) And 128
 Exponent = ONA(7) - 129 + 1023
 NNA(6) = Exponent * 2 ^ 4 And 255
 NNA(7) = (Exponent \ 2 ^ 4 And 255) Or Sign
 For X = 6 To 1 Step -1
  ONA(X) = ONA(X) * 2 ^ 1 And 255
  ONA(X) = ONA(X) Or ONA(X - 1) \ 2 ^ 7 And 255
 Next
 ONA(0) = ONA(0) * 2 ^ 1 And 255
 For X = 6 To 2 Step -1
  NNA(X) = NNA(X) Or ONA(X) \ 2 ^ 4 And 255
  NNA(X - 1) = ONA(X) * 2 ^ 4 And 255
 Next
 For X = 0 To 7
  NewNum = NewNum + Chr$(NNA(X))
 Next
 CVDMBF = CVD(NewNum)
End Function

Function CVDTPR (OldStringTP As String) As Double
 Dim X, Sign, Exponent As Integer
 Dim NewNum As String
 Static ONA(0 To 5), NNA(0 To 7)
 For X = 0 To 5
  ONA(X) = Asc(Mid$(OldStringTP, X + 1, 1))
 Next
 For X = 0 To 7
  NNA(X) = 0
 Next
 Sign = ONA(5) And 128
 Exponent = ONA(0) - 129 + 1023
 NNA(6) = Exponent * 2 ^ 4 And 255
 NNA(7) = (Exponent \ 2 ^ 4 And 255) Or Sign
 For X = 5 To 2 Step -1
  ONA(X) = ONA(X) * 2 ^ 1 And 255
  ONA(X) = ONA(X) Or ONA(X - 1) \ 2 ^ 7 And 255
 Next
 ONA(0) = ONA(0) * 2 ^ 1 And 255
 For X = 6 To 2 Step -1
  NNA(X) = NNA(X) Or ONA(X - 1) \ 2 ^ 4 And 255
  NNA(X - 1) = ONA(X - 1) * 2 ^ 4 And 255
 Next
 For X = 0 To 7
  NewNum = NewNum + Chr$(NNA(X))
 Next
 CVDTPR = CVD(NewNum)
End Function

Function MKI$ (X As Integer)
 temp$ = Space$(2)
 hmemcpy ByVal temp$, X%, 2
 MKI$ = temp$
End Function

Function MKL$ (X As Long)
 temp$ = Space$(4)
 hmemcpy ByVal temp$, X&, 4
 MKL$ = temp$
End Function

Function MKS$ (X As Single)
 temp$ = Space$(4)
 hmemcpy ByVal temp$, X!, 4
 MKS$ = temp$
End Function

Function MKD$ (X As Double)
 temp$ = Space$(8)
 hmemcpy ByVal temp$, X, 8
 MKD$ = temp$
End Function

Function MKSMBF$ (OldNumberSP As Single)
 Dim X, Sign, Exponent As Integer
 Dim OldString As String
 ReDim ONA(0 To 7)
 ReDim NNA(0 To 3)
 OldString = MKD$(CDbl(OldNumberSP))
 For X = 0 To 7
  ONA(X) = Asc(Mid$(OldString, X + 1, 1))
 Next
 Sign = ONA(7) And 128
 Exponent = ((ONA(7) And 127) * 2 ^ 4 And 255) + (ONA(6) \ 2 ^ 4 And 255)
 If Exponent Then Exponent = (Exponent + 129 - 1023) And 255
 For X = 2 To 0 Step -1
  NNA(X) = ONA(X + 4) * 2 ^ 4 And 255
  NNA(X) = NNA(X) Or ONA(X + 3) \ 2 ^ 4 And 255
 Next
 For X = 0 To 1
  NNA(X) = NNA(X) \ 2 ^ 1 And 255
  NNA(X) = NNA(X) Or NNA(X + 1) * 2 ^ 7 And 255
 Next
 NNA(2) = NNA(2) \ 2 ^ 1 And 255
 NNA(2) = NNA(2) Or Sign
 NNA(3) = Exponent
 MKSMBF$ = Space$(4)
 For X = 0 To 3
  Mid$(MKSMBF$, X + 1, 1) = Chr$(NNA(X))
 Next
End Function

Function MKDMBF$ (OldNumberDP As Double)
 Dim X, Sign, Exponent As Integer
 Dim NewNum As String
 Dim OldString As String
 Static ONA(0 To 7), NNA(0 To 7)
 OldNum# = OldNumberDP
 OldString = MKD$(OldNum#)
 For X = 0 To 7
  ONA(X) = Asc(Mid$(OldString, X + 1, 1))
 Next
 Sign = ONA(7) And 128
 Exponent = ((ONA(7) And 127) * 2 ^ 4 And 255) + (ONA(6) \ 2 ^ 4 And 255)
 If Exponent Then Exponent = (Exponent + 129 - 1023) And 255
 For X = 6 To 1 Step -1
  NNA(X) = ONA(X) * 2 ^ 4 And 255
  NNA(X) = NNA(X) Or ONA(X - 1) \ 2 ^ 4 And 255
 Next
 For X = 0 To 5
  NNA(X) = NNA(X) \ 2 ^ 1 And 255
  NNA(X) = NNA(X) Or NNA(X + 1) * 2 ^ 7 And 255
 Next
 NNA(6) = NNA(6) \ 2 ^ 1 And 255
 NNA(6) = NNA(6) Or Sign
 NNA(7) = Exponent
 MKDMBF$ = Space$(8)
 For X = 0 To 7
  Mid$(MKDMBF$, X + 1, 1) = Chr$(NNA(X))
 Next
End Function

Function MKDTPR$ (OldNumberDP As Double)
 Dim X, Sign, Exponent As Integer
 Dim NewNum, OldString As String
 Static ONA(0 To 7), NNA(0 To 5)
 OldNum# = OldNumberDP
 OldString = MKD$(OldNum#)
 For X = 0 To 7
  ONA(X) = Asc(Mid$(OldString, X + 1, 1))
 Next
 Sign = ONA(7) And 128
 Exponent = (((ONA(7) And 127) * 2 ^ 4 And 255) + (ONA(6) \ 2 ^ 4 And 255) + 129 - 1023) And 255
 For X = 5 To 1 Step -1
  NNA(X) = ONA(X + 1) * 2 ^ 4 And 255
  NNA(X) = NNA(X) Or ONA(X) \ 2 ^ 4 And 255
 Next
 For X = 1 To 4
  NNA(X) = NNA(X) \ 2 ^ 1 And 255
  NNA(X) = NNA(X) Or NNA(X + 1) * 2 ^ 7 And 255
 Next
 NNA(5) = NNA(5) \ 2 ^ 1 And 255
 NNA(5) = NNA(5) Or Sign
 NNA(0) = Exponent
 MKDTPR$ = Space$(6)
 For X = 0 To 5
  Mid$(MKDTPR$, X + 1, 1) = Chr$(NNA(X))
 Next
End Function

