Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BaseConverter
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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; }
[
+
]
Show input
Absolute running time: 0.08 sec, cpu time: 0.03 sec, memory peak: 6 Mb, absolute service time: 0,08 sec
edit mode
|
history
|
discussion
0 1 1 5 5 5 5 69