#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub dec2bin { my $bits = shift; my $str = unpack("B8", pack("F", $bits)); return $str; } sub bin2dec { return unpack("F", pack("B8", substr("0" x 8 . shift , -8))); } my @array = (0.000008,-0.000008); foreach $_ (@array){ if ($_ < 0) { print "Value: $_ is negative\n"; my $negative_b = dec2bin($_); print "Negative binary: ".$negative_b."\n"; my $negative_d = bin2dec($negative_b); print "Negative_binary back to decimal: ".$negative_d."\n"; } else { print "Value: $_ is possitive\n"; my $possitive_b = dec2bin($_); print "Possitive binary: ".$possitive_b."\n"; my $possitive_d = bin2dec($possitive_b); print "Possitive_binary back to decimal: ".$possitive_d."\n"; } } __END__ Value: 8e-06 is possitive Possitive binary: 10001101 Use of uninitialized value $possitive_d in concatenation (.) or string at negative2bin&bin2negative.pl line 31. Possitive_binary back to decimal: Value: -8e-06 is negative Negative binary: 10001101 Use of uninitialized value $negative_d in concatenation (.) or string at negative2bin&bin2negative.pl line 24. Negative_binary back to decimal: