in reply to decimal -> hex
my $address = "127.0.0.1"; # from decimal to hex: my ($a,$b,$c,$d) = $address =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/; my $hex_addr = sprintf "%02x.%02x.%02x.%02x", $a, $b, $c, $d; print "[$hex_addr]\n"; #prints "[7f.00.00.01]"; # from hex to decimal: my ($a, $b, $c, $d) = $hex_addr =~ /(\w+)\.(\w+)\.(\w+)\.(\w+)/; my $addr = hex($a). "." . hex($b) . "." . hex($c) . "." . hex($d); print "[$addr]\n"; #prints "[127.0.0.1]"
Hope it helps.
jarich
Update: Added the second part once I worked it out, but kabel beat me anyway.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: decimal -> hex
by grantm (Parson) on Oct 11, 2002 at 07:18 UTC | |
by bart (Canon) on Oct 12, 2002 at 10:12 UTC | |
by Anonymous Monk on Oct 13, 2002 at 07:27 UTC | |
by Anonymous Monk on Oct 13, 2002 at 07:34 UTC | |
by FireBird34 (Pilgrim) on Oct 11, 2002 at 16:05 UTC |