# Binary / Hex / Octal to Number

This is the script for each converter:

This post inspired me to make this.

I was only able to make the X to number, but I need to work on the number to X.

Using JS type juggling. Nice!

If it works, I use it to my advantage. If you look at my other posts, you can see that.

I guess we do inherit the parsing of numeric strings from JS, same as we inherit a lot of primitive functions from JS, but it's our numeric string format as much as theirs. It's not as if @tethrarxitet were using JS FUNCTION to do the parsing!

(By the way, I didn't realize you could say "0o" for octal; in my youth you just said "0" in front of the number for octal, which was the only non-decimal parsing option in those days. I'm sure that must still work in C, at least, because of all the old code still running out there.)

@tethrarxitet: It's a clever trick, but you should be able to write code to do the parsing yourself, digit by digit. How would you decode, let's say, 100110 binary with pencil and paper? (I picked binary because the arithmetic will be easier, not because there's anything magic about it. Powers of 16 get big quickly!)

Same way we decode base 10 (which is pretty much the default), like 1, 12, 30. It's just simple counting,
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0111 = 7
...
1111 = 15
and it follows a pattern where each digit toggles after some power of two.
It shouldn't be hard.

But again, I am super lazy, so I just research some little workarounds.

No, pfui, that's not how you read decimal or binary. When you see, e.g., "87", you don't hold out your hundred-fingered hands and hold up another finger each time you say the next number name, "one, two, three, four, ... nine, ten, eleven, ... eighty-five, eighty-six, eighty-seven." You think "the 8 means eight tens, because of where it is in the numeral, and the 7 means seven ones."

Similarly, when you see "0110" as a binary numeral, you think, "no eights, a four, a two, and no ones, so 4+2=6 decimal."

Sorry. I figured, because Scratch has the same thing, and there it is unintentional, it was the same here.

¯\_(*o*)_/¯

Well, it was sort of negatively intentional, I think, in the sense that Jens was aware that he was using JS's number parser, and if it did something he didn't like, he would have written his own instead. I figure much the same is true of Scratch. But all of us inherit the notation from C, which I believe is the first programming language to use a prepended zero to indicate a non-decimal base (octal, in the beginning).

We should accept Roman numerals in numeric slots, like Maclisp.

...right?

That would be cool.