[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 640
  • Last Modified:

Convert HEX value to a LONG value in Coldfusion

Hello,

There are several functions out there to convert HEX values to decimals, strings and floats(thanks again @_agx_) and can be found here:

http://www.cflib.org/udf/HexToDec
http://www.cflib.org/udf/hexToString
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_25617810.html

What I need to do is convert the HEX value to a LONG Value.

Thank you very much in advance!!!!!!!!!!!!!!!!!!!!!!!!!
0
stracqan
Asked:
stracqan
  • 3
  • 3
1 Solution
 
_agx_Commented:
Sorry, I missed your last post.  I don't know of any existing udf's for this one.  Assuming you have createObject() access, I'd use java.  I'd also convert it to a date object.  So you can format it however you want.

<cfset str = "(the hex value...)">
<cfset l = createObject("java", "java.lang.Long").parseLong( str, 16 )>
<cfset valueAsDate = createObject("java", "java.util.Date").init( l )>
0
 
Jones911Commented:
Well Hex is Base16, Decimal is Base 10 so:

Example 5a in Hex is 90 in decimal:

#InputBaseN("5a",16)#

Will output 90.
0
 
_agx_Commented:
@Jones911  

Unfortunately, it's not as simple as that.  I wish it were ;-) I've been working with the asker on another thread with specific test data, and the conversions just do not work out right.  Plus, CF has some issues with the Long type.  Numbers get truncated or bomb entirely once you go above Integer.MAXIMUM_VALUE (which their values routinely do ..)   So the java route is safer all around here.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
stracqanAuthor Commented:
WORKED ABOSULTELY PERFECT AGAIN!!!!!!!! In like an hour I should be finished with my algo :-)

Thank you so very much!!!
0
 
stracqanAuthor Commented:
Again, SUBERB!!!!!! Thank you  very much for all of your  help!!!
0
 
_agx_Commented:
Awesome.  BTW: It was an interesting api, so I created an algorithm too .. just for fun. If you want to compare notes, feel free to email me (address is in my profile).  I'm curious if mine works properly on real data ;-), but no pressure either way.  I'm just glad I could help. Cheers.
0
 
stracqanAuthor Commented:
Sent!!
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now