Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double calcDecimal(int exponent, int position) {
- // Base case
- char currentBit = input.charAt(position);
- if (exponent == 0) {
- if (currentBit == '1') {
- return 1;
- } else {
- return 0;
- }
- } else {
- if (currentBit == '1') {
- return Math.pow(2, exponent) + Main.calcDecimal(--exponent, ++position);
- } else {
- return Main.calcDecimal(--exponent, ++position);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement