in reply to Hex to Octet
That can be simplified to a one-liner:#!/usr/bin/perl my $hexstr = "0xb400189"; # Convert to a number in machine-byte order my $num = hex $hexstr; # Convert to a number in big-endian order my $be_num = pack("N",$num); # Extract the 4 bytes my($a,$b,$c,$d) = unpack("C4",$be_num); # And print! printf "%x.%x.%x.%x\n",$a,$b,$c,$d;
printf "%x.%x.%x.%x\n", unpack("C4",pack("N",hex $hexstr));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Hex to Octet
by Anonymous Monk on Sep 09, 2003 at 18:17 UTC | |
by Mr. Muskrat (Canon) on Sep 09, 2003 at 18:40 UTC | |
by Anonymous Monk on Sep 09, 2003 at 18:47 UTC |