Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-20-2003, 09:01 AM   #1
baby_annie
How to code in Flash
 
baby_annie's Avatar
 
Join Date: Nov 2002
Location: peaceful city
Posts: 835
Send a message via ICQ to baby_annie Send a message via MSN to baby_annie Send a message via Yahoo to baby_annie
Default decimal number to binary number ?

In ActionScript, I can use parseInt to convert binary num to decimal number. But how can I convert decimal number to binary number? I try find in AS dictionary but there isn't result.
I have an input textfield to enter the decimal number, and an other to display the binary number.
Please tell me how...Thx U,
baby_annie is offline   Reply With Quote
Old 05-20-2003, 09:07 AM   #2
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Howdy...

Try this???

http://proto.layer51.com/d.aspx?f=222
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 05-20-2003, 09:23 AM   #3
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

pixelwit did one before, was great but I didn't save the URL and I searched alot but I didn't
u can look for it with me
__________________
‚€* GOD Is Near ‚€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Old 05-20-2003, 10:19 AM   #4
baby_annie
How to code in Flash
 
baby_annie's Avatar
 
Join Date: Nov 2002
Location: peaceful city
Posts: 835
Send a message via ICQ to baby_annie Send a message via MSN to baby_annie Send a message via Yahoo to baby_annie
Default

Thx for Ur help, I will try it.
I searched in the Forum, but no thread about it excluded my thread
baby_annie is offline   Reply With Quote
Old 05-20-2003, 10:38 AM   #5
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

I know that, think he posted it withen another post not as a seperate one
think we should PM him for that
__________________
‚€* GOD Is Near ‚€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Old 03-26-2004, 10:41 PM   #6
jtarbell
Registered User
 
Join Date: Mar 2004
Location: Albuquerque, New Mexico
Posts: 1
Default decimal to binary

Here is a quick and crude method to convert a decimal number to a binary string in Flash MX:


Code:
// convert decimal number to binary string
function dec2bin(iNumber) {
	var bin = "";
	var oNumber = iNumber;
	while (iNumber>0) {
		if (iNumber%2) {
			bin = "1"+bin;
		} else {
			bin = "0"+bin;
		}
		iNumber = Math.floor(iNumber/2);
	}
	// left pad with zeros
	while (bin.length<15) {
		bin = "0"+bin;
	}
	return bin;
};
Found this thread while searching for a better version than what is posted above.
jtarbell is offline   Reply With Quote
Old 03-26-2004, 11:45 PM   #7
boyzdynasty
Senior Member
 
boyzdynasty's Avatar
 
Join Date: Aug 2002
Location: Philly
Posts: 2,583
Default

ActionScript Code:
as tags not working
... still not working
__________________
I need a new signature!
boyzdynasty is offline   Reply With Quote
Old 03-26-2004, 11:48 PM   #8
splict
spend my time in blender
 
splict's Avatar
 
Join Date: Oct 2003
Location: tampa, fl
Posts: 1,138
Default

here's one, but I just came up with it so it could very easily be very wrong I did some tests, though, and it seemed to be accurate.

[edit]seems to be right because its about the same as yours, jtarbell, just a bit slimmer[/edit]

-splict
PHP Code:
function dec2bin(num) {
    var 
bin "";
    while (
num) {
        
bin num bin;
        
num Math.floor(num 2);
    }
    return (
bin) ? bin 0;
}
trace(dec2bin(60)); 
__________________

Certified Flash MX 2004 Developer
splict is offline   Reply With Quote
Old 03-28-2004, 09:10 PM   #9
pixelwit
village halfwit
 
pixelwit's Avatar
 
Join Date: Jul 2001
Location: USA, PA
Posts: 3,330
Default

Code:
createTextField("Decimal", 10, 25, 25, 525, 20);
Decimal.text = "ten";
Decimal.type = "input";
createTextField("Binary", 20, 25, 75, 525, 20);
Binary.text = "two";
Binary.wordWrap = true;
Decimal.onChanged = function(){
	var numbr = parseInt(this.text);
	Binary.text = numbr.toString(2);
}
-PiXELWiT
http://www.pixelwit.com
__________________
There are no answers, only choices.
pixelwit is offline   Reply With Quote
Old 03-28-2004, 09:42 PM   #10
splict
spend my time in blender
 
splict's Avatar
 
Join Date: Oct 2003
Location: tampa, fl
Posts: 1,138
Default

Number.toString - thats a new one for me! Thanks Pixelwit. Silly that I didn't know that.

Still, I enjoyed figuring that out. I'm trying to learn some math again. I wish we had all these math websites back when I was in Geometry and Trig in High school.

-splict
__________________

Certified Flash MX 2004 Developer
splict is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:55 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.