Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author: Nick Kouvaris
»  Title: Znax
»  Description: Znax is a board game. Click 4 tiles of the same color and form squares as big as you can. You will erase all the tiles inside the square and collect points. Get maximum score if you make a square with game edges.
»  More by: Nick Kouvaris


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 4941 Flash Sites | 1 New Flash Links
What's New | Top 100 Flash Site

Featured Site

»  Author Agence WOP Digital Agency
»  Title: Electricdrum
»  Description: French WOP Agency, 3D websites, Flash (Papervision, Away 3D), event or institutional projects. The agency operates on all digital projects: consulting, design, graphic design, development, online communication. The WOP agency follows you on the implementation of original, creative and optimized digital projects.


Random Links | Add your own Flash Related Links
Flash Tutorials 1481 Tutorials 7 New Tutorials Added!
What's New | Top100

» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» How To Make A Fathers Day Slideshow
» How To Make A Transparent Background of Your Flash File
» Create Flash Banner With Text Disco Light Effect Today we will introduce you a Text Disco Light eff
» Unknown Tag: Title10
Random Tutorial | Add Site


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Math-Physics

Categories Conversion of Number Systems
Author: Mr.Ehab

 
Page 4
«prev 1 2 3 4 5 6 7 next»

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.

«prev 1 2 3 4 5 6 7 next»

» Level Intermediate

Added: : 2002-03-04
Rating: 5.88 Votes: 42
Hits: 1098
» Author
Student studying Computer Engineering and Graphic Design.
» Download
Download the files used in this tutorial.
Download (34 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments