Skip to main content

Convert an hexadecimal value to decimal value

Hi there,
I have a colleague who would like to convert hexadecimal value into decimal. I made some research on the internet to see how I can do that, but I kind of struggle to create a simple function !
Also one of the value need to have the formal of an IP address.
If anyone have some suggestions, please be free to share :)
Thanks in advance !
 

Brian Element Wed, 11/18/2015 - 10:05

Hi MagiBzh

Here is a short script that will take a Hex number and change it to decimal.   I am not sure if I understand the second part about the IP address.  Can you give me an example of what you are receiving and what you want returned for the IP address?

Sub Main
 Dim hexNumber
 Dim intNumber
 
 hexNumber = InputBox("Enter a Hex number")
 
 intNumber = CLng("&h" & hexNumber)
 
 MsgBox intNumber
End Sub

MagiBzh Wed, 11/18/2015 - 10:24

Hi Brian,
Thanks for replying so soon. it is entire fields actually I have to convert for two database.
I am think I am a little rusty in writting script already lol. But how do I convert the field ? by creating a new field ? What do I use as the field equation ? Or do I have to use another way ?
For the second one, here an example:
Hex value : 6701a612
After converting in Decimal, the expected value is: 103.1.166.18
 

Brian Element Wed, 11/18/2015 - 10:47

In reply to by MagiBzh

What you want to do I can help you out.  Just so I understand it, you don't really want a script but this is more creating a new field that holds the decimal information or the IP address.  Is that right? 

Brian Element Wed, 11/18/2015 - 11:24

In reply to by MagiBzh

Hi MagiBzh,

I have created two custom functions to help you out.  You can download them and save them in your project Custom Functions.ILB folder if you are using V9 or later or in V8 I think you will have to save them and then go to the Custom Function option in the Equation Editor and import them.

Once you have them set-up you will first need to create a virtual numeric field to calculate the decimal number.  Assuming that your field containing the hex number is called HEX this would be your equation: #HexToDecimal(HEX)

You would then need to create your IP address field which would be a character field with at least 16 characters to hold a full IP address.  If you called the field above HEX_TO_DECIMAL this would be your equation: #IPFromInt(HEX_TO_DECIMAL)

Let me know if you have any problems or you are getting unexpected results.

Brian

MagiBzh Wed, 11/18/2015 - 11:32

Oups I  thought I answered you ! So yes you perfectly understand what I need "creating a new field that holds the decimal information".
Thanks for the fonction, I try them right away :)

MagiBzh Thu, 02/11/2016 - 02:54

Hi,
I have error in the custom function. I think it just doesn't have the good character. For example I have those "&h".
Is it normal ?

Brian Element Thu, 02/11/2016 - 07:38

In reply to by MagiBzh

Hi MagiBzh,

Can you do a right click on the two custom functions and then save on your drive.   Import the custom function into the equation editor and it should work.  I think the problem is that on web pages & is equavalent to & so that might be the problem.  I just tried it on my machine and it loaded properly into IDEA.

Thanks

Brian