Let me tell you what numbers these systems have and the procedure I followed to convert a certain number from one system to another.
a. The decimal system takes numbers between 0 and 9 only
b. The Binary system takes 0 and 1 only
c. The Octal system that takes numbers between 0 and 7 only
d. The Hexadecimal system takes numbers between 0 to 9 in addition to the string charaters (A(10), B(11), C(12), D(13), E(14), F(15))
The procedure for converting is approximately common for all systems. I'll explain the simplest conversion (decimal to binary). If the user types 82 as a decimal number, I try to find all the numbers that are less than to this number such that these numbers are powers of 2. That is:
1, 2, 4, 8, 16, 32, 64 (and not 128)
I take 64 and divide it by 82. I notice that there is one 64 in 82. The result is 1 (first digit in the binary system). I also compute the remainder, which is 18. Then I take 32 and divide it by 18 and notice that there is no 32 in 18 and the division yields zero. So, the first two digits in the binary number are 1 and 0. I proceed in the same manner until I get the binary number: 1010010.
The FLA file is available for download. Well, all we need is a single layer made up of 5 keyframes in the main timeline. The first keyframe contains the definitions of all the functions used. I used 6 functions that do the following:
1) Function decimalToHexadecimal that converts from decimal system to Hexadecimal system
2) Function decimalToOctal that converts from decimal system to octal system
3) Function binaryToDecimal that converts from binary system to decimal system
4) Function decimalToBinary that converts from decimal system to binary system
5) Function octalToDecimal that converts from octal system to decimal system
6) Function hexadecimalToDecimal that converts from hexadecimal system to decimal system
We'll go over the scripts of all these functions line by line to understand how they execute.
I used 4 radiobuttons from Common Libraries/Smart Clips that let the user chooses among the four number systems. For instance, if he chooses Decimal number system, then the second keyframe will be executed. When the user then types in the decimal number and presses the convert button, the corresponding number is converted to binary, octal, and hexadecimal using 3 dynamic variables that exist through out the last 4 frames in the main timeline. The dynamic variables are (output1, output2, and output3).
|» Level Intermediate|
Rating: 5.95 Votes: 41
|Student studying Computer Engineering and Graphic Design.|
|Download the files used in this tutorial.|
|Download (34 kb)|
|More help? Search our boards for quick answers!|