-
Why is number 8 equal to 010 ??
Hi all,
If you try out this simple piece of code below :
Code:
var i:Number;
for(i=0;i<20;i++)
{
if(i === 010){
trace("yes");
}else{
trace("no");
}
}
you will find that for 010 === 8, yes is echoed, for 011===10 yes is echoed too and I bet there would be more such values too.
Any ideas why this is so ? How to get around this issue ?
Thanks all !
-
.
Hi,
It seems you are entering the bounds of Binary Number System although what you have done is wrong, I know not why.
https://www.mathsisfun.com/binary-number-system.html
Try this code and see what it traces
PHP Code:
var i:Number; var output:String;
for (i = 0; i < 26; i++) { if (i.toString(2) === "1000") { output = "Positive"; } else { output = "Negative"; } trace(i + "\t:\t" + output + " - " + i.toString(2)); }
Perhaps I'm mistaken too, look into octal numebrs !!!
Last edited by fruitbeard; 10-01-2015 at 11:29 AM.
-
Lifetime Friend of Site Staff
010 is 8 in octal, check out http://docstore.mik.ua/orelly/web2/action/ch04_03.htm for an explanation of numeric literals in ActionScript
When your swf2exe tool just HAS to work
there's only one choice... SWF Studio
-
Hi fruitbeard and Northcode. Thanks for that insight. It's the octal 8 but i am surprised that a notation is not used like the leading 'x' in to denote the hexdecimal numbers. Is there a way to indicate to the system that the numbers being input are not octal?
If I am taking an input from a user and I wish to check if it's the number 8 then can't the user simply fool the system by adding 010 instead? I don't think that there is a way - at least an elegant way - to disallow the first character to be a 0 in an "input box". So if I am checking for the number 8, I guess the only way around would be to get the input text and then strip off any leading zeros.
Am i thinking correct or is there a better solution to this ?
Thanks loads.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|