05-20-2003, 09:01 AM
|
#1
|
|
How to code in Flash
Join Date: Nov 2002
Location: peaceful city
Posts: 835
|
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,
|
|
|
05-20-2003, 09:07 AM
|
#2
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
|
|
|
05-20-2003, 09:23 AM
|
#3
|
|
Addicted To FLASH
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
|
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
|
|
|
05-20-2003, 10:19 AM
|
#4
|
|
How to code in Flash
Join Date: Nov 2002
Location: peaceful city
Posts: 835
|
Thx for Ur help, I will try it.
I searched in the Forum, but no thread about it excluded my thread
|
|
|
05-20-2003, 10:38 AM
|
#5
|
|
Addicted To FLASH
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
|
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
|
|
|
03-26-2004, 10:41 PM
|
#6
|
|
Registered User
Join Date: Mar 2004
Location: Albuquerque, New Mexico
Posts: 1
|
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.
|
|
|
03-26-2004, 11:45 PM
|
#7
|
|
Senior Member
Join Date: Aug 2002
Location: Philly
Posts: 2,583
|
... still not working
__________________
I need a new signature!
|
|
|
03-26-2004, 11:48 PM
|
#8
|
|
spend my time in blender
Join Date: Oct 2003
Location: tampa, fl
Posts: 1,138
|
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 % 2 + bin;
num = Math.floor(num / 2);
}
return (bin) ? bin : 0;
}
trace(dec2bin(60));
__________________

Certified Flash MX 2004 Developer
|
|
|
03-28-2004, 09:10 PM
|
#9
|
|
village halfwit
Join Date: Jul 2001
Location: USA, PA
Posts: 3,328
|
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.
|
|
|
03-28-2004, 09:42 PM
|
#10
|
|
spend my time in blender
Join Date: Oct 2003
Location: tampa, fl
Posts: 1,138
|
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
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 09:00 AM.
///
|
|