last day (15 days later) » 

8:54 PM
Yeahhh
No more yelled at.
 
we can keep going in here to not bother others
 
Yes.
Anyways.
When you call that how do you limit how much it can use?
 
@Griffin limit what?
 
What if they enter x when they say they have base 10
 
8:57 PM
What?
 
it throws an instance of std::runtime_error with the explanation "invalid character"
line 26
and since I never bothered to catch that, it says "terminate called after throwing an instance of 'std::runtime_error' what(): invalid character"
 
Yes. That makes sense.
 
But if you give it an invalid base, like base 1, it crashes (deliberately)
a.out: main.cpp:20: unsigned int parse(const char*, unsigned int): Assertion base>1' failed.
 
Yup.
 
you know, i never understood why people consider 1111 = 4 to be "base 1"
 
9:00 PM
Still stuck on main for first one because you don't list all the letters and numbers like you go
assert(parse("0",36)==0);
assert(parse("9",36)==9)
 
it's not really
but i hear that said all the time
 
That's base 2
Because there is a 1 in it.
 
@Griffin base 2? What?
 
1111.
 
no no, 1111 = 15 (base 2)
 
9:01 PM
I know
 
@StephenLin base 1 almost works. The only place it fails is 0.
 
But there are two options there are 1 and 0
Base 1 would be like 00000
= 5
Because the only option is 0.
 
oh right
actually, i guess it sort of does
 
What's base 0 then ....
 
hello ;-)
 
9:02 PM
@Griffin I thought you were converting a number in one base to a number in another base? And a number can only "have" a base if it's in a string. effectively.
 
decided to move the conversation eh?
 
Yes.
 
@Griffin there's no base 0.
 
you can have base pi fine though
 
@StephenLin can't encode zero in base 1.
 
9:03 PM
I know I was side tracked.
 
@StephenLin That sounds like fun...
 
Back on topic.
 
@Griffin so is main still confusing you?
 
Yes. I don't know how you were able to do all the letters / numbers with out doing them individually.
 
room topic changed to Working with various bases: coliru.stacked-crooked.com/… (no tags)
 
9:04 PM
assert(parse("0",36)==0);
assert(parse("9",36)==9)
assert(parse("1",36)==0);
assert(parse("2",36)==0);
assert(parse("3",36)==0);
And so on.
 
@Griffin I think there's a major misunderstanding here.
 
Okay.
 
@Griffin That's what the array is for.
 
So your just limiting what they can input right?
 
@Griffin no, all main is is tests, to make sure everything was correct. main doesn't do any "set up" at all.
 
9:05 PM
And that my friend is why it confused the fuck out of me.,
Good.
Because that was what confused me.
I didn't understand it's purpose.
Now you said " const char* lut = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";"
 
@Griffin The purpose of main()? Other than being required to run the program @Moo is using it to test the parse() function with different values.
 
the things that "limit the input" are line 26. It gets the "value" for a character, and makes sure the valid is allowed before it continues. Otherwise, it throws an exception.
 
What about lower case?
 
@Griffin The serialize function converts from int to a string-in-a-base.
The parse function converts from a string-in-a-base to an int.
 
So due to the fact that x and X have the same number
They would both count?\
As the same letter because of line 26
 
9:09 PM
@Griffin For input, yes. The const char* lut = "..." is for output. @Moo decided to output all letter-digits in upper case.
 
@Griffin yeah, see how lines 13 and 15 are the same? Those are uppercase and then lowercase.
 
@MooingDuck actually, if you think about it, base 1 doesn't work consistently because it's a hack...the only digit should be allowed is "0", but it should have the value "0" instead of "1"
@MooingDuck you only allow it to work by making an arbitrary exception that "0" in base 1 (or whatever the only literal you use is) has value 1 instead of 0
 
@StephenLin the character chosen is arbitrary, and doens't change the fact that base 1 can't represent the value zero.
 
@StephenLin Wait till I understand this to get me confused on that shit.
 
@MooingDuck or that it can only represent 0
 
9:10 PM
@StephenLin either way, 1 isn't a valid base
 
@MooingDuck if you treated it consistently with other bases, it would only represent 0
 
@StephenLin correct
 
@MooingDuck because every base only allows the range [0, b)
so yes, people that refer to "base 1" are dumb
or well, being inprecise
 
Where do you send these values to other functions. I can't find that.
 
@Griffin what other functions? The serialize function converts from int to a string-in-a-base. The parse function converts from a string-in-a-base to an int. They don't interact in any way.
to convert a string from base 33 to base 32, you'd use serialize(parse("14fc2c2ds1",33),32);
 
9:13 PM
I see now
I thought there were more functions for some reason.
 
nope. They're both simple.
 
Why do you have a reserve?
What's it for.
 
@Griffin heh, speed. I create the string, then I reserve enough space for 11 letters, then I insert the results. If I go over what's reserved, it would be slower, but still work.
 
Okay.
 
actually, in hindsight, 11 is a poor choice. 33 would be better.
 
9:16 PM
Why do you assert this
assert(value%base<36);
 
since 4290000000 to base 2 would take 32 digits.
@Griffin makes sure I didn't make a mistake in the function. If I had an error that caused me to read past the end of the array, that would tell me.
 
And what is this ret.insert(ret.begin(),lut[value%base]);
It doesn't have an = but it also doesn't have a {
 
value is the rest of the number that I haven't put in the string yet. value%base tells me the next digit to put in the string. Then lut[...] tells me what character to use for that digit. Then ret.insert(ret.begin(),...); puts that character in the beginning of the string.
Then value /= base; removes that digit from the "part of the number not in the string".
 
Okay. I have to go but I'd like to talk about this more. You know so much about this and I really want to understand this.
 
Be sure to ping me, I probably won't check this room normally.
 
10:04 PM
@Griffin all your base are belong to us: liveworkspace.org/code/3Anfx6$0
 
2 hours ago, by Mooing Duck
@Griffin yes
1 hour ago, by Mooing Duck
we moved here
 
@MooingDuck you. don't. say?
3 messages moved from Lounge<C++>
1 message moved from Lounge<C++>
 

last day (15 days later) »