| 1 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package Bit::Compare; | ||||||||||||||||||||||||||||
| 4 | { | ||||||||||||||||||||||||||||
| 5 | 2 | $Bit::Compare::VERSION = '0.001'; | |||||||||||||||||||||||||||
| 6 | } | ||||||||||||||||||||||||||||
| 7 | #ABSTRACT: Compare two "bit strings", returning differing bits | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Sub::Exporter -setup => { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | exports => [ qw/bitcompare bit/ ], | ||||||||||||||||||||||||||||
| 11 | groups => { | ||||||||||||||||||||||||||||
| 12 | default => [ qw/bitcompare/ ], | ||||||||||||||||||||||||||||
| 13 | }, | ||||||||||||||||||||||||||||
| 14 | 2 | }; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | sub bitcompare { | ||||||||||||||||||||||||||
|
Subroutine
bitcompare: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | if (@_ == 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 1 | shift; # remove class/package to support old calling forms | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 3 | my ($s1, $s2) = @_; | |||||||||||||||||||||||||||
| 22 | 3 | $s1 = bit($s1); | |||||||||||||||||||||||||||
| 23 | 3 | $s2 = bit($s2); | |||||||||||||||||||||||||||
| 24 | 3 | ▶ | return unless ($s1 and $s2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$s1 and $s2
MC/DC0%0/2
$s1 and $s2
$s1
$s2
Truth table33%1/3
A and B
A= $s1B= $s2
| |||||||||||||||||||||||||||||
| 25 | 3 | my $v = "" . join("", unpack("c*", $s1 ^ $s2)); | |||||||||||||||||||||||||||
| 26 | 3 | $v =~ s/0//g; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 3 | return length($v); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 23 | ▶ | sub bit { | ||||||||||||||||||||||||||
|
Subroutine
bit: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 23 | my ($s) = @_; | |||||||||||||||||||||||||||
| 34 | 23 | ▶ | return unless defined $s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 23 | my @a; | |||||||||||||||||||||||||||
| 36 | 23 | foreach (split(/(.{2})/, $s)) { | |||||||||||||||||||||||||||
| 37 | 216 | ▶ | next unless length("$_") > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 116 | my $v = hex($_); | |||||||||||||||||||||||||||
| 39 | 116 | my $b = unpack("B*", pack("C",$v)); | |||||||||||||||||||||||||||
| 40 | 116 | ▶ | if (length("$_") == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 16 | $b = substr($b, -4); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 116 | push(@a, split(//, $b)); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 23 | ▶ | return (wantarray ? @a : join("", @a)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | 1; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | __END__ | ||||||||||||||||||||||||||||