Skip to main content

Posts

Showing posts from December, 2012

Base Conversion in Javascript

You might think how base conversion worked out in JavaScript. Here the solution,  Number to Base Value   Number.toString([radix]); Number - Integer number that is to be converted radix - base value either 2, 8, 16 (optional parameter) Example: <script>  //INTEGER TO BASE VALUE var n = 42; document.write(n.toString(2)); document.write(n.toString(8)); document.write(n.toString(16)); //HEX TO base var h = 0xa; document.write(n.toString(2)); document.write(n.toString(8)); </script> Output: 101010 52 2a 1010 12 Any Base value to In tege r value parseInt(string, [radix]);  string - string that is to be converted. The string can be binary value, octal value or hexadecimal value   radix - base value either 2, 8, 16 (optional parameter) Example: <script>  //Binary to integer document.write(parseInt('111',2)); //Octal to integer document.write(parseInt('12',8)); //Hex to integer document.write(parseInt('0xc',16)); </script&

Exception Handling in PHP

Notices:   These are trivial, non-critical errors that PHP encounters while executing a script Example :  Accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior . Warnings: These are more serious errors Example: attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination. Fatal errors: These are critical errors Example: Instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behavior is to display them to the user when they take place. Parse Error: When we make mistake in PHP code like, missing semicolon or any unexpected symbol in code What are Exceptions? Exceptions are the PHP 5 way of flagging up an unexpected event. They contain an information m

Random Bouncing Ball Animation

Simple animation of random balls that bounces within the screen Source: #include<stdio.h> #include<graphics.h> #include<conio.h> #include<dos.h> #include<math.h> void drawBall(struct ball *b, int color); struct ball{ int x, y; int dx, dy; int radius; }; void main() { int gd=0, gm=VGAHI; int i; struct ball b[10]; initgraph(&gd, &gm, ""); for(i=1;i<=15;i++){ b[i].radius = rand()%20; b[i].x=rand()%getmaxx(); b[i].y=rand()%getmaxy(); b[i].dx=2; b[i].dy=4; } while(!kbhit()) { delay(5); cleardevice(); for(i=1;i<=15;i++) drawBall(&b[i],i); } closegraph(); } void drawBall(struct ball *b, int color){ setfillstyle(1,color); setcolor(color); fillellipse(b->x, b->y, b->radius, b->radius); if(b->x+b->radius > getmaxx() || b->x-b->radius<0) b->dx = -b->dx; if(b->y+b->radius > getmaxy() || b->y-b->radius<0) b->dy = -b->dy; b->x+=b-&g