Tuesday, 11 February 2014
How computers do Math - Arithmetic Operators Priority in C++
In basic math algebra where we have formulas with multiple arithmetic operations taking place in C++ ( and in everyday math ) we have rules on execution priority, meaning that C++ decides which operation to do first whether its addition or multiplication. When a math formula is being executed with multiple arithmetic operations taking place multiplication and division have higher priority over all, then comes addition and substraction. In the examples below you will see how computers choose which portion of the given formula to execute first, till it completes.
If a = 5, b = 10 and c = 2 calculate the given formula below
y = 3 * a + b / c - 2
In this basic formula we have all of the arithmetic operators taking place. The very first thing computers will try to solve is multiplication as we said, so in this given example the computer will firstly calculate 3 * a then right after it will calculate b / c. Since there are no more multiplication or division operators in this formula, the computer will take the result of the first calculated portion 3 * a and the result of the second calculated portion b / c and will do addition upon these. Below i have written the steps the computer would take to solve this problem.
Step1: 3 * a = 3 * 5 = 15
and since a = 5 we know that 3 * 5 = 15
Step2: b / c = 10 / 2 = 5
and since b = 10 and c = 2 we know that 10 / 2 = 5
Now since multiplication and division are done the computer takes the result from the first step and the result from the second step and does addition
Step3: Step1 + Step2 = 15 + 5 = 20
where Step1 + Step2 are the results from the steps respectively. And by doing addition from these two steps we achieve 20 as a result.
Step4: Step3 - 2 = 20 - 2 = 19
where Step3 is the result of the addition of Step1 and Step2. We substract 2 from Step3 and we have 18.
This is how computers break formulas into pieces and give priority based on rules to different operators. Its important to keep this in mind while programming large projects where we can have multiple calculations with different types of operators taking place, since the results can be different if we swap places of operators by mistake. And if we want precision in our calculations it is of good practice to put operations with higher priorities in parentheses. To clarify your mind take this example and translate it into actual C++ code and execute it to see the results. Do some experiments by swapping operators or adding more to see how the result will change based on priority rules.
PHP Basics - Syntax and tags
As you noticed in my first tutorial Getting Started with PHP - What is PHP ? we used opening and closing tags to start writting php commands. You will need these tags whenever you want to write php code :
<?php
//PHP code here
?>
Basic Printing
In the first tutorial we used to print a string on screen. To do that we used the echo command. This command is used to print and show the result of anything you want to. You can print variables ( more on variables in next tutorial ), strings and other stuff. We will get into more detail in the upcoming tutorials.Basically what we did to print that string on screen is used the echo command and the string wrapped inside double quotes.
<?php
echo "This is a string in double quotes to be printed on screen";
?>
PHP can be mixed with html elements to stylize your strings. Take a look at this example
<?php
echo "<h1>This is a h1 tag inside PHP</h1>";
?>
Keep in mind that PHP can do a lot more than just basic printing, and when you will get into more complex stuff, like calculations data processing and other things, you will need to retrieve those results with php commands and wrapped with html tags.
Go ahead and do some experiments with the echo command and with html tags inside, like styling them with CSS or inline CSS. You will see that the result will be as you would write plain HTML. This is the basic syntax in PHP, in the upcoming tutorials we will talk more about variables.
By:
Alias
On
18:01
Getting Started with PHP - What is PHP ?
Hello World. This text is meant for absolute beginners in PHP. PHP is a dynamic server sided scripting language which we can use to build simple and complex websites. Dynamic means that PHP has the ability to take decisions based on different behaviors or clicks on our website, show different portions of contents, make calculations and other great stuff.
We cannot tell how much PHP is capable of in single text, rather we will focus on how to get started with things simple PHP page and show simple text on browser.
Gathering the Tools
First of all to write code you will need an IDE with syntax highlighting and indentation. Do a search on Google for PHP IDE's and you will find plenty of them. If you are a beginner then a good choice for ( if you are a windows user ) would be Notepad++ or Programmers Notepad.As we said PHP is server sided scripting language. Server sided means that PHP code only runs in a server with appache module and packages installed. If you don't understand what this is don't worry, just go ahead and install Xampp somewhere on your computer. This program will install binaries and other stuff including PHP which we can use to actually write PHP pages. You just start the program and start the Appache module. Open your browser and in the URL bar type localhost. If you see It Work's then you have successfully installed Xampp. Congrats !
After installing this program, navigate to your installation directory and find the htdocs folder. This is the folder where we will store our projects. Create a folder inside this folder and name it whatever you like. For simple testing purpose name it mypage, or testpage.
Writing some PHP code
Now we will write simple php code to test if PHP runs perfectly. Open your favorite editor and type this line of code and save it as index.php on your early created folder in htdocs.<?php php_info(); ?>
In your browser type localhost/testpage or whatever you named your folder. Hopefully if you did everything as told, you will see a page with your PHP configuration settings which means that we can run PHP files correctly with the help of XAMPP.
Now delete everything on your index.php file and paste this code. Again save it and navigate to localhost/testpage to see the results.
<?php echo "Hello World, This is my first PHP page. Hurray !"; ?>
Congratulations on your first successfully programmed PHP page. Please refer to online documentation to proceed and subscribe to our blog for more awesome and simple upcoming tutorials.
By:
Alias
On
17:55
Monday, 10 February 2014
C++ SFML 2.0 Spritesheet Animation Class
Loading and displaying sprites with SFML 2.0 is not hard work to do, its just two functions however when it comes to animating them you will need to actually delve a little bit more deeper. I've created a basic wrapper class for SFML 2.0 which loads displays and animates spritesheets with just few lines of code.
Beginners who are finding trouble with animating their sprites could find this helpful. First of all this class implements Sprite class and Texture class, two standard SFML classes for loading and displaying sprites. I implemented functions from these two classes in one single class which loads and animates sprites.
By:
Alias
On
16:34
How to make a Game ? Steps on how to start simple
Interactive games are getting bigger and bigger. They started from a simple Pong game on a TV. Now they are pure art, with graphics, sounds, interactions and other stuff to make you feel the experience under your skin.
The simplest answer to a game is fun. How fun can fun be ? That depends on your style. Modern games are hitting the biggest market. And if you are a game developer, then you are rich. But making a game its not that simple than playing it. Even though the hard work can be payed off, you are going to get a big pain in the ass. Yes, sorry for the disclaimer but remember just one thing. Games are fun, and creating them is more than fun. Below we offer you some steps on how to enter the amazing world of game making.
By:
Alias
On
09:20
Wednesday, 14 August 2013
Introducing UMLet: excellent free UML tool
Just as the saying stands: "Reduce everything to its essence so that form harmonizes with function", graphical diagramming notations have considerably helped for better communication and understanding in Software Development.
A diagram can help us better express our ideas about Software Design without putting textual explanations. It's already confirmed that human brain better processes images than texts. That's why graphical representation through diagrams is quite effective to communicate and express our ideas either for a Software System or a Business Process.
By:
Leo
On
14:24
Tuesday, 25 June 2013
Age of Empires on Android and iOS
This news for a mobile version of Age of Empires come after 2 months when they published a remake for Age of Empires II HD. It's no wonder that Age of Empires has such a strong fan base worldwide and is widely considered as one of the best games ever. As i already said Age of Empires is one of the most successful game franchises in the market. This historical strategy game has won the heart of many fans throughout the world. Microsoft revived their Age of Empires II on April with improved graphics and available for download through Steam as Age of Empires II HD.
By:
Leo
On
04:19
Monday, 24 June 2013
Android Jelly Bean 4.2.2 coming for Samsung Galaxy S III
Android Jelly Bean 4.2.2 |
Thanks to SamMobile we already can download the pre release for Jelly Bean 4.2.2. Well, as we already know Samsung promised that it will bring the Android Jelly Bean 4.2.2 to their Samsung Galaxy S III phones immediately a while after they released their newly Samsung Galaxy S IV smartphone.
By:
Leo
On
09:24
Saturday, 8 June 2013
Tips: How to Make Money Online
Online Money |
Internet has introduced new improved business models which made information overflow in and out of organizations easier, faster and more accurate. Perhaps, it has played a role in ruining several jobs but it also opened a ways for another incoming jobs. With the introduction of Web 2.0 this has already boosted the importance of Internet opening the way for even finishing job tasks online.
By:
Leo
On
15:00
Tuesday, 4 June 2013
Unreal Engine 4 : New features and scripting systems
By:
Alias
On
17:31
Tuesday, 28 May 2013
OUYA: New Android based Game Console
OUYA Console |
It will probably be an attractive console for Indie Developers to bring their creative and innovative gameplay. OUYA Game Console would be available for just $99 and it will attempt to bring on TV screen cheaper games unlike the major Consoles and their expensive games.
By:
Leo
On
12:15
Friday, 24 May 2013
Boolean Algebra - Digital Logic
Motherboard |
In these modern days of technology, smart electronic chips have capacities to choose different types of behavior and even playing intelligent based on events that behave upon them. To do so chips use boolean algebra to compare or do branching depending on the logic that has been designed for them.
By:
Alias
On
17:44
Wednesday, 22 May 2013
Case Sample: Cinema Application SQL Queries
Cinema App Features |
With the ER Diagrams we catch many logical connections and constraints of our Application. Then, i proceeded with the conversion of ER Diagrams into Relational Schema and the actual SQL Implementation. For further read proceed here: Case Sample: Cinema Application, ER to Relational Model mapping and SQL implementation Now, i am going to implement couple of SQL queries and deduce some interesting statistics from our actual Database.
By:
Leo
On
23:54
Monday, 20 May 2013
Binary Numbers - Addition
Binary Numbers |
We can do arithmetic operations with binary numbers just like we do with decimals. Simple enough, arithmetic operations can be very straightforward we just need to follow some rules and concentration. Since we work only with two digits 0 and 1 some operations can be challenging, however a bit of concentration will allow your logic to clear its path. So lets see how electronic machines actually do math on their way.
By:
Alias
On
19:02
Sunday, 19 May 2013
Which programming language should i learn ? - Answer yourself !
Programming Languages |
So do not be trolled by the idea that there is a language that is easier and can do complex tasks. Remember a programming language is not a software. It all depends on what you are going to program. Even assembly can be easy if you use it just to multiply two numbers.
By:
Alias
On
20:01
Subscribe to:
Posts
(
Atom
)