line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bit::Manip; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
65666
|
use warnings; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
359
|
|
4
|
10
|
|
|
10
|
|
72
|
use strict; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
628
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.04'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require XSLoader; |
9
|
|
|
|
|
|
|
XSLoader::load('Bit::Manip', $VERSION); |
10
|
|
|
|
|
|
|
|
11
|
10
|
|
|
10
|
|
63
|
use Exporter; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
5145
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
15
|
|
|
|
|
|
|
bit_get |
16
|
|
|
|
|
|
|
bit_set |
17
|
|
|
|
|
|
|
bit_clr |
18
|
|
|
|
|
|
|
bit_bin |
19
|
|
|
|
|
|
|
bit_count |
20
|
|
|
|
|
|
|
bit_mask |
21
|
|
|
|
|
|
|
bit_tog |
22
|
|
|
|
|
|
|
bit_toggle |
23
|
|
|
|
|
|
|
bit_on |
24
|
|
|
|
|
|
|
bit_off |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our %EXPORT_TAGS; |
28
|
|
|
|
|
|
|
$EXPORT_TAGS{all} = [@EXPORT_OK]; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub bit_bin { |
31
|
1024
|
|
|
1024
|
1
|
476257
|
my ($data) = @_; |
32
|
1024
|
|
|
|
|
5431
|
return sprintf("%b", $data); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
sub bit_count { |
35
|
49
|
|
|
49
|
1
|
968
|
my ($n, $set) = @_; |
36
|
|
|
|
|
|
|
|
37
|
49
|
100
|
100
|
|
|
305
|
if (! defined $n || $n !~ /^\d+/){ |
38
|
2
|
|
|
|
|
14
|
die "bit_count() requires an integer param\n"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
47
|
100
|
|
|
|
86
|
$set = 0 if ! defined $set; |
42
|
|
|
|
|
|
|
|
43
|
47
|
|
|
|
|
217
|
return _bit_count($n, $set); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
sub bit_mask { |
46
|
16
|
|
|
16
|
1
|
117
|
my ($nbits, $lsb) = @_; |
47
|
16
|
|
|
|
|
87
|
return _bit_mask($nbits, $lsb); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
sub bit_get { |
50
|
21
|
|
|
21
|
1
|
12526
|
my ($data, $msb, $lsb) = @_; |
51
|
|
|
|
|
|
|
|
52
|
21
|
100
|
|
|
|
54
|
$lsb = 0 if ! defined $lsb; |
53
|
|
|
|
|
|
|
|
54
|
21
|
|
|
|
|
86
|
_bit_get($data, $msb, $lsb); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
sub bit_clr { |
57
|
25
|
|
|
25
|
1
|
17229
|
my ($data, $lsb, $nbits) = @_; |
58
|
25
|
|
|
|
|
226
|
return _bit_set($data, $lsb, $nbits, 0); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub bit_set { |
61
|
34
|
|
|
34
|
1
|
23597
|
my ($data, $lsb, $nbits, $value) = @_; |
62
|
34
|
|
|
|
|
203
|
return _bit_set($data, $lsb, $nbits, $value); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# alias bit_toggle() into play |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
*bit_toggle = \&bit_tog; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub bit_tog { |
70
|
104
|
|
|
104
|
1
|
53538
|
my ($data, $bit) = @_; |
71
|
104
|
|
|
|
|
352
|
return _bit_tog($data, $bit); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
sub bit_on { |
74
|
24
|
|
|
24
|
1
|
11287
|
my ($data, $bit) = @_; |
75
|
24
|
|
|
|
|
77
|
return _bit_on($data, $bit); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
sub bit_off { |
78
|
24
|
|
|
24
|
1
|
10866
|
my ($data, $bit) = @_; |
79
|
24
|
|
|
|
|
76
|
return _bit_off($data, $bit); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
0
|
|
|
sub _vim{}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
__END__ |