Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undo scientific notation

Status
Not open for further replies.

mcnorth

Technical User
Aug 27, 2002
17
0
0
US
The following is my feeble effort to change an MBF formated Single to an IEEE formated single. I realize none of this is very elegant but I'll save elegance for later.

The problem at this point (I'm sure there will be more) is that at the end of the routine it's in scietific notation. What I want to do is be able to see it as a number complete with decimal point etc.

(In Module)
Option Explicit

Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (lpvDest As Any, _
lpvSource As Any, ByVal cbCopy As Long)


(In Form1)
Option Explicit

Private Sub Command1_Click()
Dim MBF As Long
Dim B(3) As Byte
Dim exp As Long
Dim mant As Long
Dim SignPos As Boolean
Dim ExpNeg As Boolean
Dim Temp As Long
SignPos = True 'default sign setting

MBF = &H85F6999A
CopyMemory B(0), MBF, 4

ExpNeg = Not (B(3) Mod 2) 'ck lsb exponent

If B(2) >= &H80 Then 'ck msb mant (sign)
SignPos = False 'preserve sign
B(2) = B(2) - &H80 'take bit off
Else: End If

If ExpNeg Then
B(2) = B(2) + &H80 'put lsb of exp in msb mant
B(3) = B(3) - 1 'take it off of exp
Else: End If

B(3) = B(3) \ 2 'shift exp right

If Not SignPos Then
B(3) = B(3) + &H80 'sign neg set msb (sign in IEEE)
Else: End If

mant = B(0)
Temp = B(1)
Temp = Temp * &H100
mant = mant + Temp
Temp = B(2)
Temp = Temp * &H10000
mant = mant + Temp

exp = B(3)
exp = exp * 1000000
Text1.Text = CSng(exp + mant)

End Sub

Ideas?

Thanks!!!
 
Oops! I forgot to adjust the bias. Any way to edit this post?
 
Addressing the 'problem at this point', try changing CSng to CDec
 
Thanks strongm.

I'm afraid there are bigger problems with this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top