Convert an hexadecimal value to decimal value
Forums
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 !
Hi Brian,
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
Hi 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
Hi 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
Hi MagiBzh
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