#!/usr/bin/perl -w
#
#   CalBinaire
#   Programme Perl par Sergio Muriel
#   Etudiant Licence informatique (L2)
#   Universite de Pau (64) France
#
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#   
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
################################################################################/     




our $ans = "0"x32;
our @func = (undef,"conv_x","add_x","sous_x","mul_x","div_x",sub {exit});
do "func.pl" or die $!;
do "operations.pl" or die $!;




sub sous_x()
{
    &clear;
    my $ia = entrer_bin();
    my $ib = entrer_bin();
    $ans = sous($ia,$ib);    
}


sub conv_x()
{
    &clear;                                                                                                                                                              
    my $num = entrer_int();                                                                                                                                              
    $ans = int2bin($num);                                                                                                                                                
}	



sub add_x()
{
    &clear;
    print "Additionner $ans avec : \n";
    print "\t1) Chiffre binaire \n";
    print "\t2) Chiffre Entier (converti ensuite en binaire\n";
    print "\t3) Retour\n";
    
    $choix = "";
    do
    {
	print "Entrer une valeur entre 1 et 3 : ";
	$choix= <STDIN>;
	chomp($choix);
    }
    until ($choix eq "1" or $choix eq "2" or $choix eq "3");
    print "CHOIX : $choix\n";
    if ($choix == 3) { return $ans; }
    my $ib;
    if ($choix ==1)
    {    
	$ib = entrer_bin();
        $ib = normalise($ib);
    }
    elsif ($choix ==2)
    {
    $ib = entrer_int();                                                                                                                                              
    $ib = int2bin($ib);                              
    }

    &clear;
    print "\t$ans \n+\t$ib\n";
    print "_"x40;
    print "\n";
    $ans = add($ans,$ib);    
}



&clear();
&menu();



