Advertisement
ridjis

binaryToDecimal

Nov 25th, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. public static int binaryToDecimal(int number) {
  2.         int decimal = 0;
  3.         int binary = number;
  4.         int power = 0;
  5.  
  6.         while (binary != 0) {
  7.             int lastDigit = binary % 10;
  8.             decimal += lastDigit * Math.pow(2, power);
  9.             power++;
  10.             binary = binary / 10;
  11.         }
  12.         return decimal;
  13.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement