FUNCTION SCRIPTS
1) The script of Function decimalToHexadecimal is:function decimalToHexadecimal (number) { array5.splice(0); array4.splice(0); for (i = 0; i <= number; i ++) { binary = Math.pow (16, i); if (binary > number) { arrayelement = i  1; break; } array5 [i] = binary; } for (j = arrayelement; j >= 0; j ) { if (j == arrayelement) { binaryelement = int (number / array5 [j]); binaryremainder = int (number % array5 [j]); if (binaryelement == 10) { binaryelement2 = 'A'; } else if (binaryelement == 11) { binaryelement2 = 'B'; } else if (binaryelement == 12) { binaryelement2 = 'C'; } else if (binaryelement == 13) { binaryelement2 = 'D'; } else if (binaryelement == 14) { binaryelement2 = 'E'; } else if (binaryelement == 15) { binaryelement2 = 'F'; } else { binaryelement2 = binaryelement; } array4 [ 0 ] = binaryelement2; } else { binaryremainder1 = binaryremainder; binaryremainder = int (binaryremainder % array5 [j]); binaryelement = int (binaryremainder1 / array5 [j]); if (binaryelement == 10) { binaryelement2 = 'A'; } else if (binaryelement == 11) { binaryelement2 = 'B'; } else if (binaryelement == 12) { binaryelement2 = 'C'; } else if (binaryelement == 13) { binaryelement2 = 'D'; } else if (binaryelement == 14) { binaryelement2 = 'E'; } else if (binaryelement == 15) { binaryelement2 = 'F'; } else { binaryelement2 = binaryelement; } array4 [arrayelement  j] = binaryelement2; } } return array4.join (""); }
Explanation line by line:
1. Function header that takes one argument, which is the number the user types in the input variable.
2. Deletes all elements of array5
3. Deletes all elements of array6
4. A for repetition structure which executes (number + 1) times and initializes variable i to zero. The aim of this for structure is to initialize the elements of array5. The elements of this array are simply the powers of 16 that are assigned to the variable binary.
5. The if selection structure that tests whether binary is greater than number.
6. arrayelement is the variable that tells us the number of valid values of binary which corresponds to the position number or subscript of the last element in array5. When binary is greater than number, i must not be the subscript of the last element and hence is decremented by 1 and assigned to arrayelement.
7. The purpose of this Break statement is to terminate the for structure when binary is greater than number.
8. The statement that initializes array5.
9. A for repetition structure that uses a variable j whose initial value is arrayelement and is continuously decremented per loop.
10. If selection structure that tests if j is equal to arrayelement.
11. Divides our number by the last element in the array and truncates the decimal part by converting it to integer and assigns the last value to variable binaryelement.
12. Same as above but by finding the remainder using the modulus operator and assigning the last value to variable binaryremainder.
13. If selection structure that tests whether binaryelement is 10 or not.
14. sets binaryelement2 to be equal to character A.
Same explanation for lines 15 till 24
25. If binaryelement is neither 10, 11, 12, 13, 14, 15, set binaryelement2 to be equal to binaryelement.
26. Initializes the first element of array4 to binaryelement2. The elements of this array are the digits of the hexadecimal number.
27. Else structure corresponding to if.
28. Initializes binaryremainder1 to be equal to binaryremainder.
29. Replaces the value of binaryremainder by another value that is equal to the remainder of dividing binaryremainder by a certain element of array5.
30. Replaces the value of binaryelement by another value which is equal to the quotient of dividing binaryremainder1 by a certain element of array5.
Same explanation for lines 31 till 44 as for 14 till 25.
45. Initializes an element of array4 to be equal to binaryelement2. Notice that this array may hold string characters.
46. Displays the elements of the array in the output without being separated.
Although this may sound quite big, but it's just the same as the method I explained in the beginning of the tutorial.
» Level Intermediate 
Added: 20020304 Rating: 5.83 Votes: 42 
» 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!