Converting from Hex to IP Field

othmanyg

Registered User.
Local time
Today, 02:02
Joined
Feb 1, 2000
Messages
43
Hello good people,

I have a crystal report field that should output IP address. Now, the field is displaying the IP addresses in Hex format, what is the formula to change from Hex to IP format so the field display IPs instead of Hex?

Many thanks,:)
 
Here is a formula that I created. It proabably could be made more efficient, but it works. It assumes a text string for the IP address with no "0x" at the front of the string (see string variable hex). Hope it works for you.


stringvar hex := "ab4f34ba";
numbervar i;
stringvar subhex;
numbervar octet;
stringvar ipstring :="";
numbervar multiplier;
for i := 0 to 3
do (
subhex := mid(hex,i*2+1,1);
if subhex > "9" then
multiplier := switch(subhex = "f", 15, subhex ="e", 14, subhex ="d", 13, subhex ="c", 12, subhex ="b", 11, subhex ="a", 10)
else
multiplier := val(subhex)
;
octet := multiplier * 16;
subhex := mid(hex,i*2+2,1);
if subhex > "9" then
multiplier := switch(subhex = "f", 15, subhex ="e", 14, subhex ="d", 13, subhex ="c", 12, subhex ="b", 11, subhex ="a", 10)
else
multiplier := val(subhex)
;
octet := octet + multiplier;
if ipstring = "" then
ipstring := totext(octet,0)
else
ipstring := ipstring + totext(octet,0);
if i <> 3 then ipstring := ipstring + ".";
);
ipstring;
 

Users who are viewing this thread

Back
Top Bottom