Wednesday, April 25, 2012

Decimal to Binary - JavaScript

The typical way to convert a decimal number to binary number is to divide the decimal number (the dividend) by 2 (the divisor) and the obtained quotient will be pass on and divide by 2 again until the quotient reached 0. Then, the remainder will become the binary number of the decimal number.

Decimal Number :
Binary Number :



From the illustration, the binary of 64 is 1000000 (remainder from bottom to top). The same logic apply to decimal to hexadecimal as well.

Programming is a process of transferring observed logic into computer instructions. With the logic we observed from the above illustration, we can write a JavaScript function:

function dec2bin(num)
{
  var dividend = num;
  var divisor = 2;
  var quotient = dividend;
  var remainder;
  var binary = [];

  while(quotient>0)
  {
    remainder = quotient%divisor;
    quotient = Math.floor(quotient/divisor);
    binary.unshift(remainder);
   }
  return binary.join("");
}

In the function, it accept a decimal number. Then, assign this number to dividend and to quotient as well. We create an iteration statement to loop the process of division until the quotient is 0. The remainders are added  into an array called binary. Finally, return the binary value as string to the program.

Monday, April 23, 2012

AutoComplete feature in Browser

In order to save your time of typing repeating phrase such as user name, password, search string or some common fields that you often used, browser has include a feature called AutoComplete.

AutoCompete or sometime called AutoFill has been included in HTML 5. However, not all of the browsers supported this feature. For Mozilla Firefox, it is available from version 4 and above. And, Internet Explorer includes this feature from version 5 and above.

In Mozilla FireFox, you may enable the AutoComplete feature by configure the history setting under privacy tab. It is accessible from Tools > Options then select Privacy tab. Under the History block, choose Use custom settings for history option. And make sure you checked the checked box of Remember search and form history.




In Internet Explore, select Tools > Internet Options, then select Content tab. To enable the AutoComplete feature checked the AutoComplete checked box.

If you are using AutoComplete feature in ASP.NET, most likely you would like to enable this feature in your respective browsers. 

ASP.NET vs PHP

It is quite normal that people has confusion between ASP.NET and PHP. In fact, ASP.NET is a subset of .NET Framework and PHP is a server site programming language. At the end, they may take part in developing web application but there are not the same.

.NET Framework is a big set of classes and libraries that have been created for developing all sorts of application; such as Windows Standalone Application, Dynamic Link Library or Web Application. And, ASP.NET is a subset of this "big family". ASP.NET contains classes and libraries that related to web development.

.NET Framework consists of two parts; Framework Class Library and Common Language Runtime. In fact, it is quite similar to JAVA. The concept behind .NET Framework is to build a cross architecture application that will split the process into compiling and running code in two different mode. Let take a look at the JAVA work flow diagram.

A JAVA source code with file extension of .java is compiled into a bytecodes file with file extension of .class. And the .class object file can be executed by JVM (Java Interpreter). It is a great concept from JAVA creator to separate the code from the machine. Thus, the task of communicating with different type of CPU architecture has been passed to JVM and class file will be able to run on different type of platform without modifying the source code and re-compilation depend on architecture is not needed.

In .NET, the similar concept is adapted in order to achieve this. Let take a look at the diagram above. It is a typical process of a .NET workflow. The source code will be compiled into MSIL (Microsoft Intermediate Language). And upon execution, it will be compiled by JIT compiler, resided in .NET engine, into a native code that can be executed by that particular machine.

For ASP.NET, the common programming language being used are C# and VB.NET. The source code of these program will be compiled by different language compiler (as C# source code can be only understood by C# compiler) stated in the page directive of the top of the aspx file. This will generate a Intermediate Language file. Then, it will be executed after compile by JIT into a native code.

I hope it will be useful to those person who just wanted to start to learn .NET or ASP.NET development. In short, you may compare C# with ASP.NET vs PHP but not ASP.NET vs PHP.