For some time ive been coding arround my own projects and i stumbled upon a problem
where my engine handles numbers as a decimal precision type (double) and since last night
i finally added the hexadecimal value support in the interpreter.
But wait, doubles and hex values, does that work? yes it can and you have a few options to do so.
One of them can be find on the MSDN itself but i rly wanted a quick convertion that goes both ways.
MSDN example:
BitConverter.DoubleToInt64Bits
http://msdn.microsoft.com/en-us/library/....110).aspx
The other option i found was to make a structure with FieldOffsetAttribute with two fields; Ulong and Double.
Structure:
Then we setup our methods to do the proper assignment:
Double to hexadecimal
Hexidecimal to Double
Result:
![[Image: xmeudIZ.png]](https://i.imgur.com/xmeudIZ.png)
Now ofc ive modified my methods to my needs but the orginal creator of the method is: Greatvolk
Well, good luck ^^ -Barret
where my engine handles numbers as a decimal precision type (double) and since last night
i finally added the hexadecimal value support in the interpreter.
But wait, doubles and hex values, does that work? yes it can and you have a few options to do so.
One of them can be find on the MSDN itself but i rly wanted a quick convertion that goes both ways.
MSDN example:
BitConverter.DoubleToInt64Bits
http://msdn.microsoft.com/en-us/library/....110).aspx
Code
Dim longValue As Long
longValue = BitConverter.DoubleToInt64Bits( DblValue )The other option i found was to make a structure with FieldOffsetAttribute with two fields; Ulong and Double.
Structure:
Code
<StructLayout(LayoutKind.Explicit)> _
Structure Double2ulong
<FieldOffset(0)> Public D As Double
<FieldOffset(0)> Public UL As ULong
End StructureThen we setup our methods to do the proper assignment:
Double to hexadecimal
Code
Public Function DoubleToHex(d as Double) As String
Return New Double2ulong() With {.D = d}.UL.ToString("X")
End FunctionHexidecimal to Double
Code
Public Function HexToDouble(str as string) As Double
Return New Double2ulong() With {.UL = ULong.Parse(str, NumberStyles.AllowHexSpecifier)}.D
End FunctionResult:
![[Image: xmeudIZ.png]](https://i.imgur.com/xmeudIZ.png)
Now ofc ive modified my methods to my needs but the orginal creator of the method is: Greatvolk
Well, good luck ^^ -Barret



