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 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|