id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > test2021_01_15_HL_binaryToDecimal
prev  |  next  |  chance

Write a method that has an input parameter 'digits' that represents a BINARY number, but is ACTUALLY a long integer in base 10. Write a RECURSIVE method to compute the decimal equivalent of this binary representation. Your solution MUST be recursive with no loops of any kind. I suggest writing the recursive method as a helper-method so you don't have to use the super long name for the method. For example, the body of my method is: return biToDeci(digits); which calls the helper-method 'biToDeci' which is where I put the entire recursive solution. As a precondition you may assume the input parameter will ONLY contain the digits '0' and '1' and will be a non-negative number that fits in the 'long' data-type. FYI: MY recursive solution to this problem is a one-liner!


test2021_01_15_HL_binaryToDecimal(111) → 7
test2021_01_15_HL_binaryToDecimal(0) → 0
test2021_01_15_HL_binaryToDecimal(1) → 1

...Save, Compile, Run (ctrl-enter)

public long test2021_01_15_HL_binaryToDecimal(long digits) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 410

Copyright Nick Parlante 2017 - privacy