Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn IB Bloggers
Focal Point    Focal Point Forums  Hop To Forum Categories  iWay Software Product Forum on Focal Point    [Closed] Hexadecimal to Decimal
Go
New
Search
Notify
Tools
Reply
  
[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: 36 | Registered: July 25, 2016Reply With QuoteReport 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: 480 | Location: Toronto | Registered: June 23, 2009Reply With QuoteReport 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: 36 | Registered: July 25, 2016Reply With QuoteReport This Post
Gold 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
 


WF 8.1.05
Win8.1 / IE11
AHTML EXL2K PDF COMT WP ZIP
 
Posts: 98 | Registered: October 19, 2010Reply With QuoteReport This Post
Silver Member
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,


WebFOCUS 8105m/8201 | Windows 10
 
Posts: 37 | Location: Salt Lake City, UT, USA | Registered: November 18, 2015Reply With QuoteReport This Post
Silver 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.1.05M
Windows 2012 R2 Server
HTML, PDF, Excel
In FOCUS since 1980
 
Posts: 43 | Location: Seattle, WA | Registered: April 07, 2015Reply With QuoteReport 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: 36 | Registered: July 25, 2016Reply With QuoteReport This Post
  Powered by Social Strata  
 

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

Copyright © 1996-2017 Information Builders, leaders in enterprise business intelligence.