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  iWay Software Product Forum on Focal Point    [Closed] Hexadecimal to Decimal

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[Closed] Hexadecimal to Decimal
 Login/Join
 
Silver Member
posted
Hello,

I'm looking for some advise on converting Hex to Decimal values.

Something like '073D7AAE' needs to be converted to it's corresponding decimal '121469614'.

I want to perform this as a define or user function instead of creating temporary file for lookup.

Thanks in advance.

This message has been edited. Last edited by: Avatar,


WebFOCUS 8
Windows, All Outputs
 
Posts: 38 | Registered: July 25, 2016Report This Post
Guru
posted Hide Post
Avatar,

The following IBI Techsupport knowledge base link may help you out with this question.

Let us know if it does ( or does not).

How to convert Hex values (A2) to Decimal values (I2)

Thank you for participating in the Focal Point Forum

Kind Regards,
Tamra Colangelo
IBI Focal Point Moderator


WebFOCUS 8x - BI Portal, Developer Studio, App Studio, Excel, PDF, Active Formats and HTML5
 
Posts: 487 | Location: Toronto | Registered: June 23, 2009Report This Post
Silver Member
posted Hide Post
Tamra,

I noticed this before. This is merely doing one byte conversion but I want something with more than that.

Eg. 073D7AAE -> 121469614.

I also noted one topic doing this with temp file but I'm looking for something simple, if available.


WebFOCUS 8
Windows, All Outputs
 
Posts: 38 | Registered: July 25, 2016Report This Post
Platinum Member
posted Hide Post
The code below works for up to four hex positions. You can increase the number of positions as needed. I'm testing it here with PCD from ggsales which has several valid hex values. You may want to implement some kind of error check for invalid values (notice PCD code 'G100' is not valid hex but still shows a result).

 DEFINE FUNCTION hex2dec (hex/A4)
 hexrjust/A4 = RJUST(4,hex,'A4');
 hexchar0/A1 = EDIT(hexrjust,'$$$9'); 
 hexchar1/A1 = EDIT(hexrjust,'$$9'); 
 hexchar2/A1 = EDIT(hexrjust,'$9'); 
 hexchar3/A1 = EDIT(hexrjust,'9');
 hex2dec/P20 =   16**0 * DECODE hexchar0 ('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) 
               + 16**1 * DECODE hexchar1 ('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)  
               + 16**2 * DECODE hexchar2 ('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)  
               + 16**3 * DECODE hexchar3 ('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) 
               ; 
 END
 
 TABLE FILE ibisamp/ggsales
 SUM 
 COMPUTE Result/P20C = hex2dec(PCD);
      BY PCD
 END
 


WebFOCUS 8.2.06
 
Posts: 210 | Location: Sterling Heights, Michigan | Registered: October 19, 2010Report This Post
Master
posted Hide Post
I was able to convert Hex to Dec when using a SQL pass-through. You just need to make sure that you add a '0x' to the front of your HEX as you can see I did in the &SQLHEX variable:

 
-DEFAULTH &MYHEX = '073D7AAE'
-SET &SQLHEX = '0x' | &MYHEX;

ENGINE SQLMSS SET DEFAULT_CONNECTION YOUR_SERVER_NAME
SQL SQLMSS PREPARE SQLOUT FOR

SELECT '&MYHEX' AS HEX, CONVERT(INT, &SQLHEX.EVAL) AS DEC

END

TABLE FILE SQLOUT
PRINT *
END 



I'm sure that you could use the DB_EXPR function if you don't want to use a SQL Pass-through.

This message has been edited. Last edited by: Hallway,


Hallway

 
Prod: 8202M1
Test: 8202M4
Repository:
 
OS:
 
Outputs:
 
 
 
 
 
Posts: 608 | Location: Salt Lake City, UT, USA | Registered: November 18, 2015Report This Post
Platinum Member
posted Hide Post
Here's a way to do it in Dialogue Manager:
-* HexToDec - Hexadecimal to Decimal Conversion
-* Michael Meagher
-* DataMine, LLC

-SET &N=1;
-SET &HexArray.&N = '1';
-SET &N=&N+1;
-SET &HexArray.&N = '2';
-SET &N=&N+1;
-SET &HexArray.&N = '3';
-SET &N=&N+1;
-SET &HexArray.&N = '4';
-SET &N=&N+1;
-SET &HexArray.&N = '5';
-SET &N=&N+1;
-SET &HexArray.&N = '6';
-SET &N=&N+1;
-SET &HexArray.&N = '7';
-SET &N=&N+1;
-SET &HexArray.&N = '8';
-SET &N=&N+1;
-SET &HexArray.&N = '9';
-SET &N=&N+1;
-SET &HexArray.&N = 'A';
-SET &N=&N+1;
-SET &HexArray.&N = 'B';
-SET &N=&N+1;
-SET &HexArray.&N = 'C';
-SET &N=&N+1;
-SET &HexArray.&N = 'D';
-SET &N=&N+1;
-SET &HexArray.&N = 'E';
-SET &N=&N+1;
-SET &HexArray.&N = 'F';
-SET &N=&N+1;
-SET &HexArray.&N = 'G';

-SET &HexLength = &Hexadecimal.LENGTH;
-SET &LengthFormat = 'A'||&HexLength;
-SET &Hexadecimal = UPCASE(&HexLength,&Hexadecimal,'&LengthFormat');
-SET &J=0;
-SET &Decimal=0;

-ParseLoop
-* Parse the hexadecimal string
-* &J will be the position of &HexChar
-IF &J GT &HexLength THEN GOTO Done;
-SET &J=&J+1;
-SET &HexChar=SUBSTR(&HexLength, &Hexadecimal, &J, &J, 1, 'A1');
-SET &I=0;

-PowerSearch
-* Assign an integer value to &HexChar
-* &I will be the decimal representation of &HexChar.
-* For example &I will be 1 when HexChar is 1, and &I will be 14 when HexChar is E.
-SET &I=&I+1;
-IF &I GT 16 THEN GOTO ParseLoop;
-IF &HexChar EQ &HexArray.&I GOTO BuildDecimal;
-GOTO PowerSearch

-BuildDecimal
-* To get the actual decimal value for &HexChar we raise 16 to the power of (&HexLength-&J) 
-* and multiply by &I. Then add the results to the previous total.
-* 
-SET &Power = &HexLength-&J;
-SET &Decimal = &Decimal + &I*(16**&Power);
-GOTO ParseLoop

-Done
-TYPE &Hexadecimal
-TYPE &Decimal


WebFOCUS 8.2.03 - Production
WebFOCUS 8.2.04 - Sand Box
Windows 2012 R2 Server
HTML, PDF, Excel
In FOCUS since 1980
 
Posts: 115 | Location: Seattle, WA | Registered: April 07, 2015Report This Post
Silver Member
posted Hide Post
Thanks to all for your help and your time ...

I was able to accomplish what I wanted with dbeagan's suggestion and special thanks to dbeagan

Cheers...


WebFOCUS 8
Windows, All Outputs
 
Posts: 38 | Registered: July 25, 2016Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  iWay Software Product Forum on Focal Point    [Closed] Hexadecimal to Decimal

Copyright © 1996-2020 Information Builders