RCPPlus/Utils.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 36 CC 4 SCAR 26.4
CC
4
Cov
0%
bytes2int
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 14.0
1 package Bosch::RCPPlus::Utils;
2 use strict;
3  
4 require Exporter;
5 our @ISA = qw(Exporter);
6 our @EXPORT_OK = qw(bytes2int);
7  
8 sub bytes2int
9 {
10 my ($a, $unsigned) = @_;
11 my $back = 0;
12  
13 if ($a) {
14 my $length = scalar @{$a};
15 for (my $i = 0; $i < $length; $i++) {
16 my $idx = $length - 1 - $i;
17 my $val = $a->[$idx];
18 # back += val<<(i*8)
19 $back += $val * (256 ** $i);
20 }
21  
22 if (not $unsigned) {
23 if (($a->[0] & 0x80) > 0) {
24 # 1st bit is set --> negative number
25 my $intMax = 2 ** ($length * 8) - 1;
26 $back = ($intMax - $back + 1) * (-1);
27 }
28 }
29 }
30  
31 return $back;
32 }
33  
34 1;