# Decimal-Binary Conversion

**URL:** <https://forum.kirupa.com/t/decimal-binary-conversion/158138>\
**Category:** flash\
**Created:** [August 7, 2005, 3:36pm UTC](https://forum.kirupa.com/t/decimal-binary-conversion/158138 "2005-08-07T15:36:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chic0](https://avatars.discourse-cdn.com/v4/letter/c/c5a1d2/32.png) [@chic0](https://forum.kirupa.com/u/chic0)\
**Post date:** [August 7, 2005, 3:36pm UTC](https://forum.kirupa.com/t/decimal-binary-conversion/158138/1 "2005-08-07T15:36:31Z")

</div>

Again, reading one of the actionscript articles I ran into a script (in the [Binary-Decimal Conversion Article)](http://www.kirupa.com/developer/actionscript/binary_conversion.htm) that I didnt understand completely.

```auto
// convert decimal number to binary string
function dec2bin(iNumber) {
	var bin = "";
	var oNumber = iNumber;
	//this while method constructs a string from the number you enter as iNumber when you call the function
	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;
}

```

Could anyone explain this piece of code for me.  
Maybe by taking a decimal number as example and saying what Flash does with it, in the while loop, or smth 😊

Thanks in advance

:cap:

[size=2][font=Arial][size=2] [/size][/font][/size]
