View Single Post
  #11  
Old 06-07-2003, 06:48 AM
Lurker_005
Demi-God
 
Join Date: Jan 2002
Location: Tourist town USA
Posts: 1,671
Default

Forgot, heading is actually a float value

Since I was working in VBScript and it neglected a DecToFloat function here is what I made...

Code:
Function DecToFloat(heading)
	Dim headbin, headtmp, binexptmp, binexp, headfloat, i
			'			Convert to decimal representation of first 16 bits of a float
			headtmp=CSng(heading)
			i=512
			headbin=""
			' get whole part of number into bin-string
			Do While i >=1
				If headtmp >= i Then
					headbin=headbin & "1"
					headtmp=headtmp-i
				Else
					headbin=headbin & "0"
				End If
				i=i/2
			Loop
			
'			MsgBox headtmp & ", " & headbin     
			' add fractional part of number to the string 
			If headtmp <> 0 Then
				headbin=headbin & "."
				i=2
				Do While i <=256
					If headtmp >= 1/i Then
						headbin=headbin & "1"
						headtmp=headtmp-1/i
					Else
						headbin=headbin & "0"
					End If
					i=i*2
				Loop
			End If
'			MsgBox headbin & ", " & headtmp      
			
			' Treat the bin number as a regular number and set to 1.xxx format
			headbin=CDbl(headbin)
				i=0
			If headbin >=1 Then
				Do While headbin > 2
					headbin=headbin/10
					i=i+1
				Loop
			ElseIf headbin > 0 Then
				' already in 1.xxx or smaller
				Do While headbin <1
					headbin=headbin*10
					i=i+1
				Loop
			End If
			' make headtmp a bin-string of the F part of the float
			headtmp=""
			binexptmp=i+127
			headbin=headbin-1
'			MsgBox headbin & ", " & binexptmp      
			i=-1
			Do While i > -8
				If headbin>=10^i Then
					headtmp=headtmp & "1"
					headbin=headbin-10^i
				Else
					headtmp=headtmp & "0"
				End If
				i=i-1
			Loop
'			MsgBox headbin & ", " & headtmp      
			
			' turn binexptmp into the exp in bin-string format
			i=128
			binexp=""
			Do While i >=1
				If binexptmp >= i Then
					binexp=binexp & "1"
					binexptmp=binexptmp-i
				Else
					binexp=binexp & "0"
				End If
				i=i/2
			Loop
			
			headfloat=CDbl(binexp & headtmp) ' concentrate E and F together s is always 0 so dosen't matter
'			MsgBox "0 " & binexp & ", " & headtmp & vbCRLF & headfloat     
			'convert the bin number to a decimal for EQEmu
			i=14
			heading=0
			Do While i >=0
				If headfloat >= 10^i Then
					heading=heading+2^i
					headfloat=headfloat-10^i
				End If
				i=i-1
			Loop
			

	DecToFloat=heading
End Function
__________________
Please read the forum rules and look at reacent messages before posting.
Reply With Quote