Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
BaseConverter
//JavaScript-C24.2.0 (SpiderMonkey) print(convertFromBase("1000101", 2)); function convertFromBase(num, base) { if (!base || base < 2 || (base > 10 && base !== 16)) { return -1; } let value = 0; for (let i = num.length - 1; i >= 0; i--) { let digit = digitToValue(num[i]); if (digit < 0 || digit > base){ return -1; } let exp = num.length - i - 1; value += digit*Math.pow(base, exp); } return value; } function digitToValue(ch) { return ch; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Animal category
Rocket Science
sortStack
Futbal
123141242342
Time it has been since Tuesday, January 1st, 2019
merge json array objects based on ID
Triangle
Education-Salary
Fixed
Please log in to post a comment.