New topic: 

decimal fraction to hex

<http://forums.realsoftware.com/viewtopic.php?t=46469>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        wee_eric          Post subject: decimal fraction to hexPosted: 
Mon Jan 07, 2013 6:06 am                         
Joined: Fri Jan 11, 2008 6:33 am
Posts: 142                Is there a function in RS for this?
I need to convert something like 12.003 to hex.

thanks   
                             Top                ktekinay          Post subject: 
Re: decimal fraction to hexPosted: Mon Jan 07, 2013 8:29 am                     
            
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 339
Location: New York, NY                How about something like this:
Function DoubleToHex (value As Double) As String
  dim mb as new MemoryBlock( 8 )
  mb.LittleEndian = False
  mb.DoubleValue( 0 ) = value
  return EncodeHex( mb )
End Function

Function HexToDouble (s As String) As Double
  dim mb as MemoryBlock = DecodeHex( s )
  mb.LittleEndian = False
  return mb.DoubleValue( 0 )
End Function

This is off the top of my headed and not tested.      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top                DaveS          Post subject: 
Re: decimal fraction to hexPosted: Mon Jan 07, 2013 9:28 am                     
            
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4388
Location: San Diego, CA                Convert to "HEX" or convert it to its 
internal memory representation?

And if the latter... to what end.... if that data is going to be transferred 
and read on a different platform... that representation may  or may not be 
compatible (big endian vs little endian for starters)      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                wee_eric          Post subject: 
Re: decimal fraction to hexPosted: Mon Jan 07, 2013 11:02 am                    
     
Joined: Fri Jan 11, 2008 6:33 am
Posts: 142                Thanks ktekinay, I can use that function.

I just need the 2byte representation (bigendian) of the decimal fraction part 
of a number (say 1.3 - I just need the .3).

I adapted your function to this and it works a treat
dim mb as new MemoryBlock( 8 )
mb.LittleEndian = False
mb.DoubleValue( 0 ) = value
return Mid(EncodeHex( mb ),4,4)


many thanks
eric   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to