Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int binaryToDecimal(int number) {
- int decimal = 0;
- int binary = number;
- int power = 0;
- while (binary != 0) {
- int lastDigit = binary % 10;
- decimal += lastDigit * Math.pow(2, power);
- power++;
- binary = binary / 10;
- }
- return decimal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement