• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Convert Decimal to Hex

Explorer ,
Jun 08, 2007 Jun 08, 2007

Copy link to clipboard

Copied

I use an LDAP database that stores values in decimal format, but to display these values to the end user, I want them in Hex.

For example.

50699 becomes C60B
and
18743297 becomes 11E0001

Is there a function built into CF that allows me to do this conversion? I can't seem to find one. Or will I have to write a cfscript or javascript function to do this for me?

-xtort
TOPICS
Advanced techniques

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jun 08, 2007 Jun 08, 2007
I just found that in Ben Forda's book. That got it, thanks!!

Votes

Translate

Translate
Guest
Jun 08, 2007 Jun 08, 2007

Copy link to clipboard

Copied

Try BinaryEncode / BinaryDecode

<CFSET HEX=BinaryEncode("50699","HEX")>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 08, 2007 Jun 08, 2007

Copy link to clipboard

Copied

I don't think that will work, as I am trying to go from decimal to hex. When I try to use your code it states that the value is not in binary (1 or 0) and therefore wont convert. Thank you for the suggestion though!!

Parameter 1 of function BinaryEncode, which is now "50699", must be a valid binary object.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 08, 2007 Jun 08, 2007

Copy link to clipboard

Copied

<cfoutput>
#uCase(formatBaseN(50699, 16))#<br/>
#uCase(formatBaseN(18743297, 16))#<br/>
</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 08, 2007 Jun 08, 2007

Copy link to clipboard

Copied

Check cflib.org. Bound to be something there.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 08, 2007 Jun 08, 2007

Copy link to clipboard

Copied

Dan Bracuk wrote:
> Check cflib.org. Bound to be something there.

Or the documentation. The function the OP is looking for is
formatBaseN(). This allows conversion from decimal to any other base.
And the corresponding inputBaseN() function which goes the other way.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 08, 2007 Jun 08, 2007

Copy link to clipboard

Copied

> Is there a function built into CF that allows me to do this conversion? I
> can't seem to find one.

Did you look in the documentation?

http://livedocs.adobe.com/coldfusion/7/htmldocs/00000467.htm

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 08, 2007 Jun 08, 2007

Copy link to clipboard

Copied

I just found that in Ben Forda's book. That got it, thanks!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 08, 2007 Jun 08, 2007

Copy link to clipboard

Copied

LATEST
> I just found that in Ben Forda's book. That got it, thanks!!

Glad you found it.

livedocs is a good resource for those who are patient: it's a *very* slow
site, especially given the simple pages it's delivering. But it's got
everything you need (the annotations on the pages are often more useful
that the "official" line, btw).

A good entry point to the most important parts of livedocs are these:
http://ray.camdenfamily.com/downloads/functions.html
http://ray.camdenfamily.com/downloads/tags.html

It cuts down quite a bit of the waiting. They;re also good lists to scan
to get a handle on what CF can do, at least at an executive summary level.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation