Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] HexaDecimal to Decimal Conversion

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] HexaDecimal to Decimal Conversion
 Login/Join
 
Member
posted
Hi All,
I am using webfocus7.1.3. I need to convert a hexadecimal value to Decimal value.Can anyone help me in this issue.

Thanks in advance.

This message has been edited. Last edited by: Kerry,
 
Posts: 10 | Registered: September 29, 2008Report This Post
<JG>
posted
Open your documentation and lookup

HEXBYT and BYTVAL
 
Report This Post
Expert
posted Hide Post
John,

I am not sure that is what TNVP is really looking for? More like a hex string to find the decimal equivalent?

TNVP,

This is a basic maths problem in which you will have to interpret each component of your hex string to obtain the decimal equivalent. You could do that via a simple decode. If you have a max size of the hex string (say x'FF') then you could use an external decode file.

So many ways and methods of doing what I think that you are asking, that really it is best for you to initially analyse your specific requirements and work towards your solution with that in mind.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Guru
posted Hide Post
if its a single one-off result you need you can use the google calculator


Developer Studio 7.64
Win XP
Output: mostly HTML, also Excel and PDF

"Never attribute to malice that which can be adequately explained by stupidity." - Heinlein's Razor
 
Posts: 285 | Location: UK | Registered: October 26, 2007Report This Post
<JG>
posted
Tony, Quite correct, hadn’t had enough coffee.

To make up here's a DM solution.

-SET &HEX = 'ABC123';
-SET &HEXx= &HEX.LENGTH;
-SET &HEXc=1;
-SET &DEC=0;
-REPEAT ENDHEX &HEXx.EVAL TIMES
-SET &HEXa= SUBSTR(&HEX.LENGTH, '&HEX.EVAL', &HEXc, &HEXc, 1, 'A1');
-SET &POWER= &HEX.LENGTH - (&HEXc -1);
-SET &HEXv= DECODE &HEXa('0' 0 '1' 1 '2' 2 '3' 3 '4' 4 '5' 5 '6' 6 '7' 7 '8' 8 '9' 9 'A' 10 'B' 11 'C' 12 'D' 13 'E' 14 'F' 15);
-SET &DECx = (&HEXv * (16 ** (&POWER -1)));
-SET &DEC = &DEC + &DECx ;
-POWER
-SET &HEXc= &HEXc +1;
-ENDHEX
-TYPE &DEC
 
Report This Post
Expert
posted Hide Post
JG, I only noticed because the match sticks hadn't broken this moring Wink

To complement your DM solution, here's one using a flat file format from my library of useful code (uses autoprompt). It could be used to dump the Hex strings into a temporary table and then pull out the Integer values. If the user enters an invalid character then '0' is substituted.

-SET &Dummy = &Hexstr.Please enter a hex string.;
-* Sting prefixed with 'x' as REVERSE doesn't seem to like pure numerics!
-SET &Hexlen = ARGLEN(999, 'x          &Hexstr.EVAL', 'I3');
-SET &Hexout = UPCASE(10,REVERSE(10,REVERSE(&Hexlen,'x          &Hexstr.EVAL','A&Hexlen.EVAL'),'A10'),'A10');
FILEDEF HEXTOINT DISK HEXTOINT.ftm
-RUN
EX -LINES 5 EDAPUT MASTER,HEXTOINT,CF,MEM,FILENAME=HEXTOINT, SUFFIX=FIX,$
SEGNAME=ONE, SEGTYPE=S0, $
  FIELD=HEXSTRING,     ,A10  ,A10  ,$
SEGNAME=TWO, PARENT=ONE, OCCURS=10, POSITION=HEXSTRING,  SEGTYPE=S, $
  FIELD=HEXCHAR,       ,A1   ,A1   ,$
-RUN
-WRITE HEXTOINT &Hexout
-RUN
TABLE FILE HEXTOINT
PRINT HEXCHAR
      COMPUTE VAL/I3 = IF HEXCHAR FROM 'A' TO 'F' THEN BYTVAL(HEXCHAR, 'I3') - 55
                  ELSE IF HEXCHAR FROM '1' TO '9' THEN BYTVAL(HEXCHAR, 'I3') - 48
                  ELSE 0;
      COMPUTE CNT/I2 = IF HEXSTRING EQ LAST HEXSTRING THEN CNT + 1 ELSE 0;
      COMPUTE POWER/I2 = 9 - CNT;
      COMPUTE HEXINT/D20c = VAL * (16 ** POWER);
   BY HEXSTRING
ON TABLE HOLD
END
-RUN
-*HOLD
TABLE FILE HOLD
SUM HEXINT
 BY HEXSTRING
END
-RUN

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Expert
posted Hide Post
Plus a quick example of using it from extracted output -
EX -LINES 5 EDAPUT MASTER,HEXTOINT,CF,MEM,FILENAME=HEXTOINT, SUFFIX=FIX,$
SEGNAME=ONE, SEGTYPE=S0, $
  FIELD=HEXSTRING,     ,A10  ,A10  ,$
SEGNAME=TWO, PARENT=ONE, OCCURS=10, POSITION=HEXSTRING,  SEGTYPE=S, $
  FIELD=HEXCHAR,       ,A1   ,A1   ,$
-RUN
TABLE FILE CAR
BY COUNTRY
ON TABLE SAVE AS HEXTOINT
END
-RUN
TABLE FILE HEXTOINT
PRINT HEXCHAR
      COMPUTE VAL/I3 = IF HEXCHAR FROM 'A' TO 'F' THEN BYTVAL(HEXCHAR, 'I3') - 55
                  ELSE IF HEXCHAR FROM '1' TO '9' THEN BYTVAL(HEXCHAR, 'I3') - 48
                  ELSE 0;
      COMPUTE CNT/I2 = IF HEXSTRING EQ LAST HEXSTRING THEN CNT + 1 ELSE 0;
      COMPUTE POWER/I2 = 9 - CNT;
      COMPUTE HEXINT/D20c = VAL * (16 ** POWER);
   BY HEXSTRING
ON TABLE HOLD
END
-RUN
TABLE FILE HOLD
SUM HEXINT
 BY HEXSTRING
END
-RUN

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Virtuoso
posted Hide Post
Tony

It's not fair....

You did not even give TNPV the change to work this out after your firts suggestion, which should have been enough.




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

 
Posts: 2387 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006Report This Post
Expert
posted Hide Post
Too true Frank, but then he did ask fairly nicely and also JG had given him a suggestion before me. I was just adding to JG's suggestion as a possible TABLE process option Wink Razzer

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Platinum Member
posted Hide Post
Because WebFOCUS has so many manuals, HEXBYT and BYTVAL/BITVAL will be found under functions. If you are using DevStudio the DEFINE tool has Functions will step you through the code.


WebFOCUS & ReportCaster 8.1.05, 7.7.03 - AIX/LINUX, FOCUS 7.6.13 MVS, Output PDF, XLS-XLSX, DOCX and HTML
 
Posts: 146 | Location: Atlanta, GA | Registered: May 31, 2007Report This Post
Member
posted Hide Post
Thank you JG,T,nubi,Frank,Rhonda for your valuable suggestions.

I have a hexadecimal color code.I want to calculate its RGB equivalent.
e.x. #ffffff to 255 255 255

This is the issue for which i need guidance.

Thanks in advance
 
Posts: 10 | Registered: September 29, 2008Report This Post
Gold member
posted Hide Post
Is this a one time thing?
Do you need to use it for your style sheet?
is this what you need : http://www.drpeterjones.com/colorcalc/ ?


PROD: WebFOCUS 7.1.0 on Linux/Tomcat 5.5.12 (standalone)/Informix on AIX
TEST: WebFOCUS 7.1.3 on Linux/Tomcat 5.5.16 (standalone)/Informix on AIX
 
Posts: 53 | Location: Montreal,Quebec,Canada | Registered: February 13, 2006Report This Post
Guru
posted Hide Post
 
Posts: 252 | Location: USA | Registered: April 15, 2003Report This Post
<JG>
posted
That is actually a slightly different issue as you are not actually converting
a hex string to decimal you are converting 3 parts of a hex string to three
decimals and to be honest it is much easier to achive.

All you have to do is create a decode table either as a flat file or as inline code
then edit the hex value into its 3 pairs and decode them to the decimal values.
finally combine the decimals to give the RBG

-SET &HEXIN='#ffffff';
-SET &CNTR=0;
-REPEAT ENDREPEAT 3 TIMES
-SET &CNTR = &CNTR +1;
-SET &HEX= IF &CNTR EQ 1 THEN UPCASE(2, EDIT(&HEXIN,'$99'), 'A2') ELSE
- IF &CNTR EQ 2 THEN UPCASE(2, EDIT(&HEXIN,'$$$99'), 'A2') ELSE
- UPCASE(2, EDIT(&HEXIN,'$$$$$99'), 'A2');
-SET &DEC&CNTR.EVAL = DECODE &HEX(
- '00' '00'
.
.
- 'fe' '254'
- 'ff' '255' ELSE '000');
-ENDREPEAT
-SET &RGB = '&DEC1.EVAL' | ' ' | '&DEC2.EVAL' | ' ' | '&DEC3.EVAL';

I'm sure you can fill in decode list.

The same basic code could be put into a define quite easily.
 
Report This Post
Guru
posted Hide Post
quote:
Originally posted by T.N.V.Pandian:
Thank you JG,T,nubi,Frank,Rhonda for your valuable suggestions.

I have a hexadecimal color code.I want to calculate its RGB equivalent.
e.x. #ffffff to 255 255 255

This is the issue for which i need guidance.

Thanks in advance


not a problem i just thought that if it was a one off thing you needed to do its better to use something like google as its designed for quick ad-hoc requests...

the other thing you could download is Paint.net, this is a freeware Photoshop copy but more importantly it has a colour pallete which you can enter Hex or RGB into- so you can get the values that way and actually see the colour at the same time.....


Developer Studio 7.64
Win XP
Output: mostly HTML, also Excel and PDF

"Never attribute to malice that which can be adequately explained by stupidity." - Heinlein's Razor
 
Posts: 285 | Location: UK | Registered: October 26, 2007Report This Post
Expert
posted Hide Post
Here's a Defined function that can be used in Dialogue Manager or WebFOCUS code - it converts one Hex value to one decimal value and can be called multiple time to convert a hex colour value to decimal:

DEFINE FUNCTION HEXTODEC(INHEX/A2)
INHEXA/A1 = EDIT(INHEX, '9$');
INHEXB/A1 = EDIT(INHEX, '$9');

INDECA/I2 =
  IF INHEXA GE '0' AND INHEXA LE '9' THEN EDIT(INHEXA) ELSE DECODE INHEXA ('A' 10, 'B' 11, 'C' 12, 'D' 13, 'E' 14, 'F' 15 ELSE 0);
INDECB/I2 =
  IF INHEXB GE '0' AND INHEXB LE '9' THEN EDIT(INHEXB) ELSE DECODE INHEXB ('A' 10, 'B' 11, 'C' 12, 'D' 13, 'E' 14, 'F' 15 ELSE 0);

HEXTODECN/I3 = (INDECA * 16) + INDECB ;
HEXTODEC/A3  = EDIT(HEXTODECN);
END
-RUN

-SET &COLOUR_HEX = '#F0F9FC';

-SET &COLOUR_DEC =
-  HEXTODEC(EDIT('&COLOUR_HEX.EVAL','$99$$$$')) | ' ' |
-  HEXTODEC(EDIT('&COLOUR_HEX.EVAL','$$$99$$')) | ' ' |
-  HEXTODEC(EDIT('&COLOUR_HEX.EVAL','$$$$$99'));

-TYPE COLOUR &COLOUR_HEX = &COLOUR_DEC



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Expert
posted Hide Post
Decimal to Hex defined function:

DEFINE FUNCTION DECTOHEX(INDEC/I3)
INDECD/I2 = INDEC / 16;
INDECR/I2 = IMOD(INDEC, 16, 'I2');

INHEXA/A2 =
  IF INDECD GE 0 AND INDECD LE 9 THEN EDIT(INDECD) ELSE DECODE INDECD (10 ' A', 11 ' B', 12 ' C', 13 ' D', 14 ' E', 15 ' F' ELSE '00');
INHEXB/A2 =
  IF INDECR GE 0 AND INDECR LE 9 THEN EDIT(INDECR) ELSE DECODE INDECR (10 ' A', 11 ' B', 12 ' C', 13 ' D', 14 ' E', 15 ' F' ELSE '00');

DECTOHEX/A2 = EDIT(INHEXA,'$9') | EDIT(INHEXB,'$9');
END
-RUN

-SET &COLOUR_DEC = '240 249 252';

-SET &DEC1 = EDIT('&COLOUR_DEC.EVAL','999$$$$$$$$');
-SET &DEC2 = EDIT('&COLOUR_DEC.EVAL','$$$$999$$$$');
-SET &DEC3 = EDIT('&COLOUR_DEC.EVAL','$$$$$$$$999');

-SET &COLOUR_HEX = '#' | DECTOHEX(&DEC1) | DECTOHEX(&DEC2) | DECTOHEX(&DEC3);

-TYPE COLOUR &COLOUR_DEC = &COLOUR_HEX



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] HexaDecimal to Decimal Conversion

Copyright © 1996-2020 Information Builders