Search tutorials
4) Function decimalToBinary has the following script:
function decimalToBinary (number) {
array1.splice(0);
array.splice(0);
for (i = 0; i <= number; i ++) {
binary = Math.pow (2, i);
if (binary > number) {
arrayelement = i - 1;
break;
}
array [i] = binary;
}
for (j = arrayelement; j >= 0; j --) {
if (j == arrayelement) {
binaryelement = int (number / array [j]);
binaryremainder = int (number % array [j]);
array1[ 0 ] = binaryelement;
} else {
binaryremainder1 = binaryremainder;
binaryremainder = int (binaryremainder % array [j]);
binaryelement = int (binaryremainder1 / array [j]);
array1 [arrayelement - j] = binaryelement;
}
}
return array1.join ("");
}
This function has the same script as function decimalToOctal but with powers of 2.
5) Function octalToDecimal has the script:
function octalToDecimal (number) {
array9.splice(0);
array8.splice(0);
for (i = 0; i <= length (number) - 1; i ++) {
array8 [i] = Math.floor (number / Math.pow (10, length (number) - i - 1)) - Math.floor (number / Math.pow (10, length (number) - i)) * 10;
}
decimal1 = 0;
for (j = 0; j < array8.length; j ++) {
array9 [j] = Math.pow (8, array8.length - j - 1);
decimal = array9 [j] * array8 [j];
decimal1 += decimal;
}
return decimal1;
}
This function has the same script as function binaryToDecimal but with powers of 8.
| » Level Intermediate |
|
Added: 2002-03-04 Rating: 6.08 Votes: 40 |
| » Author |
| Student studying Computer Engineering and Graphic Design. |
| » Download |
| Download the files used in this tutorial. |
| Download (34 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!