Advertisement
ArtisOracle

Untitled

Feb 21st, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. public static double calcDecimal(int exponent, int position)  {
  2.         // Base case
  3.         char currentBit = input.charAt(position);
  4.         if (exponent == 0) {
  5.             if (currentBit == '1') {
  6.                 return 1;
  7.             } else {
  8.                 return 0;
  9.             }
  10.         } else {
  11.             if (currentBit == '1') {
  12.                 return Math.pow(2, exponent) + Main.calcDecimal(--exponent, ++position);
  13.             } else {
  14.                 return Main.calcDecimal(--exponent, ++position);
  15.             }
  16.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement