line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bit::Manip; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
18092
|
use warnings; |
|
10
|
|
|
|
|
11
|
|
|
10
|
|
|
|
|
263
|
|
4
|
10
|
|
|
10
|
|
29
|
use strict; |
|
10
|
|
|
|
|
11
|
|
|
10
|
|
|
|
|
476
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.03'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require XSLoader; |
9
|
|
|
|
|
|
|
XSLoader::load('Bit::Manip', $VERSION); |
10
|
|
|
|
|
|
|
|
11
|
10
|
|
|
10
|
|
36
|
use Exporter qw(import); |
|
10
|
|
|
|
|
8
|
|
|
10
|
|
|
|
|
3661
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
14
|
|
|
|
|
|
|
bit_get |
15
|
|
|
|
|
|
|
bit_set |
16
|
|
|
|
|
|
|
bit_clr |
17
|
|
|
|
|
|
|
bit_bin |
18
|
|
|
|
|
|
|
bit_count |
19
|
|
|
|
|
|
|
bit_mask |
20
|
|
|
|
|
|
|
bit_toggle |
21
|
|
|
|
|
|
|
bit_on |
22
|
|
|
|
|
|
|
bit_off |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our %EXPORT_TAGS; |
26
|
|
|
|
|
|
|
$EXPORT_TAGS{all} = [@EXPORT_OK]; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub bit_bin { |
29
|
1024
|
|
|
1024
|
1
|
292197
|
my ($data) = @_; |
30
|
1024
|
|
|
|
|
5123
|
return sprintf("%b", $data); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
sub bit_count { |
33
|
49
|
|
|
49
|
1
|
656
|
my ($n, $set) = @_; |
34
|
|
|
|
|
|
|
|
35
|
49
|
100
|
66
|
|
|
255
|
if (! defined $n || $n !~ /^\d+/){ |
36
|
2
|
|
|
|
|
12
|
die "bit_count() requires an integer param\n"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
47
|
100
|
|
|
|
67
|
$set = 0 if ! defined $set; |
40
|
|
|
|
|
|
|
|
41
|
47
|
|
|
|
|
192
|
return _bit_count($n, $set); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
sub bit_mask { |
44
|
16
|
|
|
16
|
1
|
40
|
my ($nbits, $lsb) = @_; |
45
|
16
|
|
|
|
|
105
|
return _bit_mask($nbits, $lsb); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
sub bit_get { |
48
|
20
|
|
|
20
|
1
|
8002
|
my ($data, $msb, $lsb) = @_; |
49
|
|
|
|
|
|
|
|
50
|
20
|
100
|
|
|
|
43
|
$lsb = 0 if ! defined $lsb; |
51
|
|
|
|
|
|
|
|
52
|
20
|
|
|
|
|
90
|
_bit_get($data, $msb, $lsb); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
sub bit_clr { |
55
|
25
|
|
|
25
|
1
|
9249
|
my ($data, $lsb, $nbits) = @_; |
56
|
25
|
|
|
|
|
157
|
return _bit_set($data, $lsb, $nbits, 0); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
sub bit_set { |
59
|
34
|
|
|
34
|
1
|
7779
|
my ($data, $lsb, $nbits, $value) = @_; |
60
|
34
|
|
|
|
|
152
|
return _bit_set($data, $lsb, $nbits, $value); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
sub bit_toggle { |
63
|
48
|
|
|
48
|
1
|
10829
|
my ($data, $bit) = @_; |
64
|
48
|
|
|
|
|
97
|
return _bit_toggle($data, $bit); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
sub bit_on { |
67
|
24
|
|
|
24
|
1
|
5517
|
my ($data, $bit) = @_; |
68
|
24
|
|
|
|
|
65
|
return _bit_on($data, $bit); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
sub bit_off { |
71
|
24
|
|
|
24
|
1
|
5649
|
my ($data, $bit) = @_; |
72
|
24
|
|
|
|
|
54
|
return _bit_off($data, $bit); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
0
|
|
|
sub _vim{}; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |