Jump to content
Server Maintenance This Week. ×

Hex to Decimal from a list


IanMaz

This topic is 1530 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi,

I have a list, return delimited of Hex values.  I am trying to figure out how to convert them to decimal.

I found a custom function that does a great job of the conversion but only for one line.

Case ( IsEmpty ( _hex ) ; Let ([ _result = $cf.hex.result; $cf.hex.result = "" ; $cf.hex.depth = "" ]; _result ) ;

Let ([
    _alpha = "0123456789ABCDEF" ;
    _hex = Case ( $cf.hex.depth ; _hex ; Filter ( Upper ( _hex ) ; _alpha )) ;
    $cf.hex.result = $cf.hex.result + ( Position ( _alpha ; Right ( _hex ; 1 ) ; 0 ; 1 ) - 1 )* 16^(0+$cf.hex.depth) ;
    $cf.hex.depth = $cf.hex.depth + 1
];
    hex2num ( Left ( _hex ; Length ( _hex ) - 1 )) )
)

I cant figure out how to make it convert the entire list.

Sample (full list is about 700 lines) of the list:
0000
000D
002D
004C
0069
0084
009E
00B6
00BC
00BD

Any suggestions would be great.

Thanks,

Ian

Link to comment
Share on other sites

You will need to loop through the list in some way. How you do that depends a lot on what you are doing with them after. The easiest way for you may be a script.

Essentially, you can get to something similar this:

hex2num ( GetValue ( $hexList ; $valueNumber ) )

 

Here is what a script may look like:

Set Variable [ $hexList ; Value: Substitute ( "0000 000D 002D 004C 0069 0084 009E 00B6 00BC 00BD" ; " " ; ¶ ) ] 
Set Variable [ $hexCount ; Value: ValueCount ( $hexList ) ] 

Loop
	 
	Set Variable [ $valueNumber ; Value: $valueNumber + 1 ] 
	Set Variable [ $currentNumber ; Value: hex2num ( GetValue ( $hexList ; $valueNumber ) ) ] 
	Set Variable [ $numberList ; Value: List ( $numberList ; $currentNumber ) ] 
	 
	Exit Loop If [ $valueNumber ≥ $hexCount ] 
	 
End Loop
 
<insert whatever else you need to do with this list> 
 
Exit Script [ Text Result:    ] 



 

At the end, before the Exit Script you will need to do whatever it is you are doing with that list of values. But the $numberList variable should have a list of the numbers. You could also import that list into a table, have a field that does the calculation for you, and then go from there... Again, just depends on what you are doing with the list.

  • Thanks 1
Link to comment
Share on other sites

Two notes:

1. Beware of custom functions that use script variables (prefixed with $ or $$). Especially if they don't take care to reset these variables at the end.

2. If you're doing this in a script, then you don't need a custom function; you can put all the required logic - including the conversion to decimal - in the script.

 

Edited by comment
  • Like 1
Link to comment
Share on other sites

Thanks for the tip.  I made sure they reset themselves.

Also its only acting on one record and one field at a time.

Good point, ill integrate that into the script.

 

My next biggest challenge is figuring out how to convert the original file to hex.

What I thought was a correct decoding, turns out to be off on a number of lines.

The original file comes from an old application from the late 90s (cant change it).

The text looks to be unicode or some version of that.

I can convert it using a C++ console app to text (decimal) but I wanted to do it all in FileMaker.

Never ends does it!

 

Thanks again!

Link to comment
Share on other sites

This topic is 1530 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.