# parseInt() problem

**URL:** https://forum.kirupa.com/t/parseint-problem/13436
**Category:** flash
**Created:** [February 13, 2003, 6:01am UTC](https://forum.kirupa.com/t/parseint-problem/13436 "2003-02-13T06:01:35Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![toh](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@toh](https://forum.kirupa.com/u/toh)
#### Post date: [February 13, 2003, 6:01am UTC](https://forum.kirupa.com/t/parseint-problem/13436/1 "2003-02-13T06:01:35Z")

</div>

trace(parseInt(1010,2)) =10  
trace(parseInt(10102,2))=10  
trace(parseInt(21010,2))=NaN

it seems parseInt stop when it meet 2. but why, 2 is invalid for binary, so why 10102 doesn’t give NaN, but 10 ??

and what should i do to checkwhether that number is invalid for certain base. eg, 4 is invalid for base 4 number.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 6:13am UTC](https://forum.kirupa.com/t/parseint-problem/13436/2 "2003-02-13T06:13:31Z")

</div>

my GUESS (just a guess) is that flash reads the binary from left to right, so it ignores the 2 at the end of the statement and stops there. But if you put it at the beginning of the string, it ignores the first digit stops and does not get to read the rest and assumes it is not a number (NaN)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 6:25am UTC](https://forum.kirupa.com/t/parseint-problem/13436/3 "2003-02-13T06:25:22Z")

</div>

yeah, i agree, thats what i mean in first post.  
what i think now to check whether is the number valid for its base is using substring, because i do that in java, but not sure how to do that in flash yet.

from help file, i see flash seems to has substring as well, never use it before.

anyway, thanx lost for replyig. 😛

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 6:45am UTC](https://forum.kirupa.com/t/parseint-problem/13436/4 "2003-02-13T06:45:06Z")

</div>

No problem. I haven’t too much experience with the substring method in Flash either, so I can’t help you there.

I wish you luck though.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 7:06am UTC](https://forum.kirupa.com/t/parseint-problem/13436/5 "2003-02-13T07:06:00Z")

</div>

Howdy…

What about this??? I am not sure if this is what you want, but I just made a simple example that checks the validity of the input numbers… See if this is what you are looking for… Oh, I see the same posting from [AS.org](http://AS.org)… Should I call this crossposting, or not??? 😃

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 7:24am UTC](https://forum.kirupa.com/t/parseint-problem/13436/6 "2003-02-13T07:24:07Z")

</div>

yeah, thats kinda what i want. but if i want say base 16, we gonna write charAt many time.

what i think is we check every word for the number and compare it to our base. the result return invalid as it meet number which is same or bigger than the base.  
but i haven’t done it yet.😛

by the way, thanx. your replying let me learn one more new thing, charAt.:love:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 7:27am UTC](https://forum.kirupa.com/t/parseint-problem/13436/7 "2003-02-13T07:27:59Z")

</div>

I love charAt(), I use it a lot in text effects through AS and JS 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 7:48am UTC](https://forum.kirupa.com/t/parseint-problem/13436/8 "2003-02-13T07:48:50Z")

</div>

Okay… 16… Hopefully this one works right… Just did fix it with ord() function to check the ASCII value…

charAt… Hehe… as long as the string itn’t too long… Know what I mean, right??? But then… I am not going to be the one who’s counting all the characters… Flash player does all the job… :evil:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 7:55am UTC](https://forum.kirupa.com/t/parseint-problem/13436/9 "2003-02-13T07:55:21Z")

</div>

That is really nice code Cyan. 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 8:02am UTC](https://forum.kirupa.com/t/parseint-problem/13436/10 "2003-02-13T08:02:02Z")

</div>

thats correct, but again, if i have the base and the number for the users to input. then users can input whatever base(2-36)and number they like.  
then this method become a little bit insufficient.

again thanx for replying, and let me learn one more new thing, ord.:love:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 8:27am UTC](https://forum.kirupa.com/t/parseint-problem/13436/11 "2003-02-13T08:27:51Z")

</div>

lostinbeta…

Thank you, sire… 😊 Just trying to return all the favors that I have gotton… I:-)

toh…

I am not quite getting what your just said…

> if i have the base and the number for the users to input. then users can input whatever base(2-36)and number they like.  
> Can you repharase this??? I cannot really imagine what kind inputs you want to verify… Can you also show me the variation of possible user input??? When you said 2-36, you meant 2-16, right???

PS\>\> What part of ASIA are you from??? Just curious…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 8:31am UTC](https://forum.kirupa.com/t/parseint-problem/13436/12 "2003-02-13T08:31:09Z")

</div>

LOL… sire???

And… for the user to input their own things can’t you just have some kind of checkbox type thing and depending on which checkbox is checked, the code will be validated for that base by calling on a specific function.

(I really have no clue what I am talking about, just shooting ideas)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 8:39am UTC](https://forum.kirupa.com/t/parseint-problem/13436/13 "2003-02-13T08:39:33Z")

</div>

Hehe… What about Masta??? 😉

Yup… Having that kind of restriction will help to minimize the error when coding and can be more efficiently managed…

Well… Maybe you can create a generic function that gets the input string and the base to check with, but I guess I am too lazy to do that… :bandit: But then, it won’t be too much of trouble to create one as long as you understand the logic behind of it, right??? (I am not trying to solve your problem here… I am trying to help you so that you can understand and learn what needs to be done…)

> (I really have no clue what I am talking about, just shooting ideas)  
> Don’t you really have no idea why??? Because it’s almost 4AM here and we need more coffee… I:-)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 8:45am UTC](https://forum.kirupa.com/t/parseint-problem/13436/14 "2003-02-13T08:45:04Z")

</div>

> \*Originally posted by CyanBlue \*  
> \*\*Don’t you really have no idea why??? Because it’s almost 4AM here and we need more coffee… I:-) \*\*

LOL… so true, so true. 3:45am. I don’t drink coffee though, I am a natural born insomniac. Sleep is one thing I can’t have ☹

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 8:58am UTC](https://forum.kirupa.com/t/parseint-problem/13436/15 "2003-02-13T08:58:54Z")

</div>

Don’t drink coffee??? Good for you… Coffee doesn’t do any good anyways… 😉 But then, I can live without the sleep, but I cannot live without coffee… :bad:

Guess you are single, right??? If you have a husband/wife, he/she won’t let you do this and help you to get to sleep… But then, my wife already gave up on me… So… 8]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 9:01am UTC](https://forum.kirupa.com/t/parseint-problem/13436/16 "2003-02-13T09:01:55Z")

</div>

I have a girlfriend of 2 years, she gets mad at me when I don’t sleep, but theres nothing I can do about it, I have a sleeping disorder and am against taking medications for anything (I am totally weird if you haven’t figured out already).

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 9:05am UTC](https://forum.kirupa.com/t/parseint-problem/13436/17 "2003-02-13T09:05:43Z")

</div>

Um… Okay… You are weird if you say so… =)

There is another weird thing… I saw the thread again and there was one hour difference… It’s 4AM in VA as it is in PA, right??? and the forum said that it is 3AM… So, I had to change the GMT-5 to GMT-4… Hm… Strange… Well… Hopefully, the sun will shine again in two hours or so, and then I can go get some sleep… Well… You… Hm… you do what you gotta do… 😛

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 9:07am UTC](https://forum.kirupa.com/t/parseint-problem/13436/18 "2003-02-13T09:07:27Z")

</div>

Yeah, that happens a couple times. It used to do it to me every other week then switch back, but then it stopped. Really weird problem, but it has to do with the server since it goes by the servers GMT time. I wouldn’t worry about it 🙂

(I think we may have gotten off track)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 9:39am UTC](https://forum.kirupa.com/t/parseint-problem/13436/19 "2003-02-13T09:39:57Z")

</div>

Yes… I think toh will be real mad when he sees what we are doing… :beam:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 13, 2003, 10:57am UTC](https://forum.kirupa.com/t/parseint-problem/13436/20 "2003-02-13T10:57:48Z")

</div>

its so good to see you two getting along so well ![](http://userpages.umbc.edu/~tmccau1/images/smilies/bigsmile.gif)

[Next page](https://forum.kirupa.com/t/parseint-problem/13436.md?page=2)
