# Binary « Actionscript Programming « Flash Tutorials

Home
Flash Tutorials
 1 Actionscript Programming 2 Animals 3 Animation 4 Colors 5 Design 6 Effects 7 Game Cartoon 8 Humans 9 Models 10 Nature 11 Operations 12 Shapes
 Flash Tutorials » Actionscript Programming » Binary

### 1. Building a Binary Clock    actionscript.org

Here I've told Flash that I am creating my own function called getTime(). A function is a snippet of code that you are planning to use more than once, so you wrap it up in a function declaration and give it a name. I gave it the name "getTime" since that describes what it is supposed to do. There are only two custom functions in this program, but if you were writing something larger, you might get confused if you didn't name your functions in ways that described their purpose. With that said, let's give getTime() some code to execute.

### 2. kirupa.com - Binary-Decimal Conversion    kirupa.com

This number is equal to 158. How did I get that? Well, if you follow the table that I showed you in the beginning, the first digit is 1, followed by 2, and so on. Each place where there is a one, you add the number in that place to your total. So, since there's a 0 in the "1's" place, we don't add 1, but since there's a 1 in the "2's" place, we will add 2. There's a 1 in each of these places: 2, 4, 8, 16, and 128, so, 2+4+8+16+128=158. That's so easy isn't it? Here, try this one: 101010101. By the way, when doing this while at the computer, the scientific mode of Windows Calculator has a feature to convert between hexadecimal, decimal, octal, and binary. You should have gotten 341 if you did it right. That was easy wasn't it? To convert from decimal is much harder. You take the next lowest place value from your number (unless your number is the same as a place value, such as 32), and you divide your number by that place, take the remainder, rinse and repeat until you get to 1. So, if our number was 100, we would divide it by 64, and get 36. We would then divide that by 32, and get 4. We divide 4 by 4, and get 1. Then we make our number and put a 1 in every place that we divided by. So, 100 in binary is 1100100.

 java2s.com  | Contact Us | Privacy Policy Copyright 2009 - 12 Demo Source and Support. All rights reserved. All other trademarks are property of their respective owners.