definitemaybe has asked for the wisdom of the Perl Monks concerning the following question:
The output is below. icarus# ./test.pl 01001000000111110100111100000000 þÿþþÿþþþþþþÿÿÿÿÿþÿþþÿÿÿÿÿÿÿÿÿÿÿÿ The small test program is below. #!/usr/bin/perl use Validator; my $suspect = '72.31.79.5'; my $suspect2 = '255.255.255.0'; $obj = Validator->new(); $obj->is_hostaddress($suspect, $suspect2); The subroutine from the module is below. sub is_hostaddress { my $self = shift if ref($_[0]); my $ipaddr = shift; my $netmask = shift; return unless defined($ipaddr) && defined($netmask); my $binipaddr = unpack('B32', pack('C4C4C4C4', split(/\./, $ip +addr))); my $binnetmask = unpack('B32', pack('C4C4C4C4', split(/\./, $n +etmask))); my $result = $binipaddr & $binnetmask; my $result2 = $binipaddr | ~ $binnetmask; print $result; print "\n"; print $result2; print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bitwise Complement
by Roy Johnson (Monsignor) on Aug 17, 2007 at 20:34 UTC | |
by definitemaybe (Initiate) on Aug 17, 2007 at 21:17 UTC | |
|
Re: Bitwise Complement
by dwm042 (Priest) on Aug 17, 2007 at 22:10 UTC |