Created
October 24, 2016 22:26
-
-
Save spaced-out-factory/afa0f3a50737c79e2a11fa4cd84c06fc to your computer and use it in GitHub Desktop.
Binary converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| binary = "1111" | |
| position = 0 | |
| values = [] | |
| sum = 0 | |
| for i = 0; i < binary.length; i++ | |
| position++ | |
| if number(binary[i]) | |
| if position > 1 | |
| values.push(position * 2) | |
| else | |
| values.push(1) | |
| endif | |
| endif | |
| endfor | |
| for i = 0; i < values.count(); i++ | |
| sum += values[i] | |
| endfor | |
| print(sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment