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
August 17, 2016, 08:52 AM
Avatar
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
August 17, 2016, 09:44 AM
dbeagan
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).
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:
August 17, 2016, 08:06 PM
Michael L Meagher
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
August 18, 2016, 10:42 AM
Avatar
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