Hack Forums
[.NET] Double To Hexadecimal Convertion [Src included] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Double To Hexadecimal Convertion [Src included] (/showthread.php?tid=4435372)

Pages: Pages 1 2


Double To Hexadecimal Convertion [Src included] - TheBarret - Sep 7, 2014

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/system.bitconverter.doubletoint64bits(v=vs.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 Structure

Then 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 Function

Hexidecimal to Double
Code
Public Function HexToDouble(str as string) As Double
    Return New Double2ulong() With {.UL = ULong.Parse(str, NumberStyles.AllowHexSpecifier)}.D
End Function

Result:
[Image: xmeudIZ.png]

Now ofc ive modified my methods to my needs but the orginal creator of the method is: Greatvolk

Well, good luck ^^ -Barret


* - SIM-1456245 - Sep 7, 2014

Well done Barret, you did it again, you posted one if those things that makes a lot of frustration, but yet again, no replies. You people should be ashamed.


* - Cornflower Blue இڿڰۣ-ڰۣ— - Sep 7, 2014

(Sep 7, 2014 07:52 AM)Electroalek Wrote:  Well done Barret, you did it again, you posted one if those things that makes a lot of frustration, but yet again, no replies. You people should be ashamed.

There isn't no reply's because this is not a rat source or a RunPE.


* - LordCoder - Sep 7, 2014

(Sep 7, 2014 08:17 AM)Cornflower Blue Wrote:  There isn't no reply's because this is not a rat source or a RunPE.

Or a crypter, DDoS'er, multi tool for l33t h4xx0r kids... That kind of people yeah. Barret this source is very useful, I also had to deal with hex numbers and they were pretty difficult to do what you want to do. Your posts deserve more popularity.


* - Cornflower Blue இڿڰۣ-ڰۣ— - Sep 7, 2014

(Sep 7, 2014 08:20 AM)LordCoder Wrote:  Or a crypter, DDoS'er, multi tool for l33t h4xx0r kids... That kind of people yeah. Barret this source is very useful, I also had to deal with hex numbers and they were pretty difficult to do what you want to do. Your posts deserve more popularity.

int to hex is easy to do, never tried float to hex.


* - TheBarret - Sep 7, 2014

There was a typo in the hex string to double method, its fixed now. ^^


* - Cornflower Blue இڿڰۣ-ڰۣ— - Sep 7, 2014

(Sep 7, 2014 08:31 AM)TheBarret Wrote:  There was a typo in the hex string to double method, its fixed now. ^^

You need to read my thread, would be a awesome update for your Tango engine.
https://hackforums.net/showthread.php?tid=4433686


* - TheBarret - Sep 7, 2014

(Sep 7, 2014 08:32 AM)Cornflower Blue Wrote:  You need to read my thread, would be a awesome update for your Tango engine.
https://hackforums.net/showthread.php?tid=4433686

Yeah ive read some parts of it indeed, it does catches my intrest Cornz.

We could merge somekind of sub-version of the new engine with your project i suppose.


* - Cornflower Blue இڿڰۣ-ڰۣ— - Sep 7, 2014

(Sep 7, 2014 08:36 AM)TheBarret Wrote:  Yeah ive read some parts of it indeed, it does catches my intrest Cornz.

We could merge somekind of sub-version of the new engine with your project i suppose.

I didn't make it, Microsoft did, it has the same method as GDI, but uses the GPU for rendering. If you want your Tango game engine thing pristine, you should add this Win2D.


* - TheBarret - Sep 7, 2014

(Sep 7, 2014 08:39 AM)Cornflower Blue Wrote:  I didn't make it, Microsoft did, it has the same method as GDI, but uses the GPU for rendering. If you want your Tango game engine thing pristine, you should add this Win2D.

I'll look into it cornz, first i need to get a grasp how basics work i cannot just drive off without knowing ^^


* - SIM-1456245 - Sep 7, 2014

(Sep 7, 2014 08:46 AM)TheBarret Wrote:  I'll look into it cornz, first i need to get a grasp how basics work i cannot just drive off without knowing ^^

On top of that you said that you are not the most up to date with the newest GDI trends.


* - TheBarret - Sep 7, 2014

(Sep 7, 2014 09:09 AM)Electroalek Wrote:  On top of that you said that you are not the most up to date with the newest GDI trends.

ehm yeah i just wrote that? whats different of "not knowing" and "not up to date"


* - SIM-1456245 - Sep 7, 2014

(Sep 7, 2014 09:19 AM)TheBarret Wrote:  ehm yeah i just wrote that? whats different of "not knowing" and "not up to date"

Was talking about your, not interested to learn attitude that you had about GDI today, but nvm. And because this new tech uses the GPU, I don't really see how that will improve performance on my shitty GPU, off topic ofc.


* - IAmNotHere - Sep 7, 2014

Thank you at: TheBarret, for this code.


* - SaketSaket - Sep 7, 2014

Nice addition to our knowledge.... Thanks ;)