$crc=255; $data[0]=readByte(); do { $_=sprintf("%08b",readByte()); # BYTE1 $byte2=''; while (m/(.)/g) { if ($1 == 0) { $byte2.='00000000';} else { $byte2.=sprintf("%08b",readByte());} # positions bytes } $data[pos($byte2)]=readByte() while ($byte2=~m/(1)/g); # put data value into @data on the correct position readByte(); if ($crc>0) {print "ERROR: CRC (POS:".pos($f).')'; exit; } # crc check $crc=255; # ---- USE DATA => DELETED -------- $data[0]=readByte(); } while ($data[0]<255); } sub readByte { unless ($f=~m/(.)/gs) {print "Last data structure not complete !"; exit;} my $x=ord($1); $crc^=$x; # CRC for my $r(1..8) { if (($crc&1)>0) {$crc=($crc>>1)^0x8c;} else {$crc=$crc>>1;} } return ($x); }