Page 509 - computer science (868) class 11
P. 509

124                  }
                  125              }

                  126              System.out.println("Decimal Value : "+ deci);
                  127          }

                  128
                  129          void hextodeci(String hex)

                  130          {
                  131              String digits = "0123456789ABCDEF";
                  132              int i,deci,val=0;

                  133              char c;

                  134              hex = hex.toUpperCase();
                  135              for ( i = 0; i < hex.length(); i++)
                  136              {

                  137                  c = hex.charAt(i);
                  138                  deci = digits.indexOf(c);

                  139                  val = 16*val + deci;
                  140              }

                  141              System.out.println("Decimal Value : "+ val);
                  142          }

                  143
                  144          void other_deci()

                  145          {
                  146              int ch,t,num;

                  147              String hexdec;
                  148              Scanner sc = new Scanner(System.in);

                  149              System.out.println("Enter 1 for Binary to Decimal");
                  150              System.out.println("Enter 2 for Octal to Decimal");

                  151              System.out.println("Enter 3 for Hexadecimal to Decimal");
                  152              System.out.println("Enter 4 for Exit");

                  153              ch=sc.nextInt();
                  154              switch(ch)

                  155              {
                  156                  case 1 :    System.out.println("Enter number to convert : ");
                  157                      num=sc.nextInt();





                                                                                                                       507
                                                                                                      Sample Projects  507
   504   505   506   507   508   509   510   511   512   513   514