Translate

Monday 9 July 2012

Write java code to print following pattern

..........
.........
........
.......
......
.....
....
...
..
.
Solution:

class Pattern4
{
public static void main(String args[])
{
for(int i=0;i<10;i++)
{
for(int j=i;j<10;j++)
{
System.out.print(".");
}
System.out.println();
}
}
}



Write java code to reverse a given string using "StringBuffer" class


import java.io.*;

class ReverseString
{
public static void main(String args[]) throws IOException
{
String str;
System.out.println("Enter a string");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
StringBuffer sb=new StringBuffer(str);
String revstr=new String(sb.reverse());
System.out.println("Reverse of "+str+" is "+revstr);
}

}

Write java code to reverse a given number


import java.io.*;

class ReverseNum
{
public static void main(String args[]) throws IOException
{
int num,rem,revnum=0,originalnum;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num=Integer.parseInt(br.readLine());
originalnum=num;
while(num>0)
{
rem=num%10;
num=(num-rem)/10;
revnum=revnum*10+rem;
}
System.out.println("Reverse of "+originalnum+" is "+revnum);
}
}

Saturday 7 July 2012

Write java code to find the Smallest of 3 numbers using ternary operator


import java.io.*;

class Small
{
public static void main(String args[]) throws IOException
{
int num1,num2,num3,small_num;
System.out.println("Enter first number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num1=Integer.parseInt(br.readLine());
System.out.println("Enter second number");
num2=Integer.parseInt(br.readLine());
System.out.println("Enter third number");
num3=Integer.parseInt(br.readLine());
small_num = (num1 < num2) ?( (num1<num3) ? num1:num3):(num2<num3?num2:num3);
System.out.println("The Smallest Number is: "+small_num);
}

}

Write java code to find the Biggest of 3 numbers using ternary operator


import java.io.*;

class Big
{
public static void main(String args[]) throws IOException
{
int num1,num2,num3,big_num;
System.out.println("Enter first number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num1=Integer.parseInt(br.readLine());
System.out.println("Enter second number");
num2=Integer.parseInt(br.readLine());
System.out.println("Enter third number");
num3=Integer.parseInt(br.readLine());
big_num = (num1 > num2) ?( (num1>num3) ? num1:num3):(num2>num3?num2:num3);
System.out.println("The Biggest Number is: "+big_num);
}

}

Write java code to obtain absolute value of given number using "ternary(?)" operator


import java.io.*;

class Ternary
{
public static void main(String args[]) throws IOException
{
int num,k;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num=Integer.parseInt(br.readLine());
k = num < 0 ? -num : num;   //get absolute value of num
System.out.println("Absolute value of "+num+" is "+k);
}

}

The ? operator

Java includes a special ternary (three-way) operator that can replace certain types of if-then-else statements. This operator is the ?, and it works in Java much like it does in C,C++, and C#. It can seem somewhat confusing at first, but the ? can be used very effectively once mastered. The ? has this general form:

expression1 ? expression2 : expression3

Here, expression1 can be any expression that evaluates to a boolean value. If expression1 is true, then expression2 is evaluated; otherwise expression3 is evaluated. The result of the ? operation is that of the expression evaluated. Both expression2 and expression3 are required to return the same type, which can't be void.
Here is an example of the way that the ? is employed:

ratio = denom == 0 ? 0 : num/denom;

When Java evaluates this assignment expression, it first looks at the expression to the left of the question mark. If denom equals zero, then the expression between the question mark and the colon is evaluated and used as the value of the entire ? expression. If denom does not equal zero, then the expression after the colon is evaluated and used for the value of the entire ? expression. The result produced by the ? operator is then assigned to ratio.

Friday 6 July 2012

Write java code to check whether given number is an Armstrong number or not


import java.io.*;

class ArmStrong
{
public static void main(String args[]) throws IOException
{
int num,rem,sum=0,originalnum;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num=Integer.parseInt(br.readLine());
originalnum=num;
while(num>0)
{
rem=num%10;
num=(num-rem)/10;
sum=sum+(rem*rem*rem);
}
if(originalnum==sum)
System.out.println("Armstrong Number!");
else
System.out.println("Not an Armstrong Number!");
}

}

Thursday 5 July 2012

Write java code to print following pattern

     *
    * *
   * * *
  * * * *
 * * * * *

Solution:
class Pattern3
{
public static void main(String args[]) 
{
for(int i=1;i<6;i++)
{
for(int j=1;j<=i;j++)
{
if(j==1)
{
for(int k=6-i;k>0;k--)
{
System.out.print(" ");
}
}
System.out.print("* ");
}
System.out.println();
}
}
}

Write java code to print following pattern:

         *
       **
     ***
   ****
 *****

Solution:

class Pattern2
{
public static void main(String args[])
{
for(int i=1;i<6;i++)
{
for(int j=1;j<=i;j++)
{
if(j==1)
{
for(int k=6-i;k>0;k--)
{
System.out.print(" ");
}
}
System.out.print("*");
}
System.out.println();
}
}

}

Write java code to check whether given number is prime or not


import java.io.*;

class CheckPrime
{
public static void main(String args[]) throws IOException
{
int num,i;
System.out.println("Enter a number:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num=Integer.parseInt(br.readLine());
for(i=2;i<num;i++)
{
if(num%i==0)
{
System.out.println("Not Prime");
break;
}
}
if(i==num)
{
System.out.println("Prime");
}
}

}

Write java code to print Fibonacci series


import java.io.*;

class Fibonacci
{
public static void main(String args[]) throws IOException
{
int limit;
System.out.println("Enter Limit:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
limit=Integer.parseInt(br.readLine());
int series[]=new int[limit];
series[0]=0;
series[1]=1;
for(int i=2;i< limit;i++)
{
series[i]=series[i-1]+series[i-2];
}
System.out.println("Fibonacci Series upto " + limit);
                for(int i=0; i< limit; i++)
{
                       System.out.println(series[i]);
}

}

}

Wednesday 4 July 2012

Write java code to print following pattern:

1
12
123
1234
12345
123456
1234567
12345678
123456789

Solution:

class Pattern1
{
public static void main(String args[])
{
for(int i=1;i<10;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}

Write java code to check whether the given string is palindrome or not

import java.io.*;
class Palindrome
{
public static void main(String args[]) throws IOException
{
String str;
System.out.println("Enter a string");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
StringBuffer sb=new StringBuffer(str);
String revstr=new String(sb.reverse());
if(revstr.equalsIgnoreCase(str))
System.out.println("Palindrome String!");
else
System.out.println("Not a Palindrome String!");
}
}

Write java code to check whether the given number is palindrome or not

import java.io.*;
class Palindrome
{
public static void main(String args[]) throws IOException
{
int num,rem,revnum=0,originalnum;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num=Integer.parseInt(br.readLine());
originalnum=num;
while(num>0)
{
rem=num%10;
num=(num-rem)/10;
revnum=revnum*10+rem;
}
if(originalnum==revnum)
System.out.println("Palindrome Number!");
else
System.out.println("Not a Palindrome Number!");
}
}

Write java code to calculate factorial of any given number using recursion

import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException
{
int num;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num=Integer.parseInt(br.readLine());
if(num==0)
{
System.out.println("Factorial of 0 is: 1");
}
else
{
System.out.println("Factorial of "+num+" is: "+fact(num));
}
}
public static int fact(int num)
{
if(num==1)
return num;
else
return num*fact(num-1);
}
}

Tuesday 3 July 2012

Write java code to calculate factorial of any given number

import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException
{
int num,f=1;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num=Integer.parseInt(br.readLine());
if(num==0)
{
System.out.println("Factorial of 0 is: 1");
}
else
{
for(int i=num;i>0;i--)
{
f=f*i;
}
System.out.println("Factorial of "+num+" is: "+f);
}
}
}

Friday 15 June 2012

Variable declaration in Java

Following is the general form of a variable declaration:

type var-name

Here, type specifies the type of variable being declared, and var-name is the name of the variable. If you want to declare more than one variable of the specified type, you may use comma-separated list of variable names. Java defines several data types, including integer, character, and floating-point. 
Consider the following program.

class Example
{
    public static void main(String args[])
    {
         int num;          // This declares a variable called num
         num = 100;    // This assigns num the value 100
         System.out.println("This is num: " + num);
    }
}

When you run this program, you will see the following output:

This is num: 100

The first new line in the program is shown here:
int num;     //This declares a variable called num

This line declares an integer variable called num. Java requires that variables be declared before they are used. The keyword int specifies an integer type.
In the program, the line
num = 100;    //this assigns num the value 100
assigns to num the value 100. In java, the assignment operator is a single equal sign.

The next line of code outputs the value of num preceded by the string "This is num: "
System.out.println("This is num: " + num);
In this statement, the plus sign causes the value of num to be appended to the string that precedes it, and then  the resulting string is output. This approach can be generalized. Using the + operator you can string together as many items as you want within a single println() statement.



Tuesday 12 June 2012

Java's main() method

public static void main(String args[])
This line begins the main() method. All java applications begins execution by calling main(). The public keyword is an access specifier, which allows the programmer to control the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared. In this case, main() must be declared as public, since it must be called by the code outside of its class when the program is started. The keyword static allows main() to be called without having to instantiate a particular instance of the class. This is necessary since main() is called by Java interpreter before any objects are made. The keyword void simply tells the compiler that main() does not return a value. As stated, main() is the method called when a Java application begins. Java is case-sensitive. Thus, Main is different from main. It is important to understand that the Java compiler will compile classes that do not contain a main() method. But Java interpreter has no way to run these classes. So, if you had typed Main instead of main, the compiler would still compile your program. But the Java interpreter would report an error because it would be unable to find the main() method.
Any information that you need to pass to a method is received by variables specified within the set of parentheses that follow the name of the method. These variables are called parameters. In main(), there is only one parameter. String args[] declares a parameter named args, which is an array of instances of the class String. In this case, args receives any command-line arguments present when the program is executed.    

Sunday 10 June 2012

Types of Comments in Java

Consider the following sample program:

/*
This is a simple Java program.
Call this file "Example.java".
*/

class Example
{
    //Your program begins with a call to main().
    public static void main(String args[])
   {
      System.out.println("This is a simple Java program.");
   }
}

The program begins with the following lines:
/*
This is a simple Java program.
Call this file "Example.java".
*/

This is a comment. The contents of the comment are ignored by the compiler. Instead, a comment describes or explains the operation of the program to anyone who is reading its source code. In real applications, comments generally explain how some part of the program works or what a specific feature does.
Java supports 3 types of the comments. The one shown at the top of the program is called multiline comment. This type of comment must begin with /* and end with */. Anything between these two comment symbols is ignored by the compiler. As the name suggests, a multiple comment may be several lines long.

The second type of the comment supported by java is the single line comment, shown here:

    //Your program begins with a call to main().

A single line comment begins with a // and ends at the end of the line. As a general rule, programmers use multiline comments for longer remarks and single line comments for brief, line by line descriptions.

The third type of comment is called a documentation comment. This type of comment is used to produce an HTML file that documents your program. The documentation comment begins with a /** and ends with a */. Here is an example of a documentation comment for a class:

/**
* This class draws a bar chart.
* @author author_name
* @version 3.2
*/





Saturday 9 June 2012

A simple Java program

/*
This is a simple Java program.
Call this file "Example.java".
*/

class Example
{
    //Your program begins with a call to main().
    public static void main(String args[])
   {
      System.out.println("This is a simple Java program.");
   }
}

Entering the program
For this example, the name of the source file should be Example.java. Let's see why.
In Java, a source file is officially called a compilation unit. It is a text file that contains one or more class definitions. The Java compiler requires that a source file use the .java filename extension. 

Compiling the Program
To compile the Example program, execute the compiler, javac, specifying the name of the source file on the command line, as shown here:

C:\>javac Example.java

The javac compiler creates a file called Example.class that contains the bytecode version of the program. As we know, the Java bytecode is the intermediate representation of your program that contains instructions the Java interpreter will execute. Thus, the output of javac is not code that can be directly executed.

To actually run the program, you must use Java interpreter, called java. To do so, pass the class name Example as a command line argument, as shown here:

C:\>java Example

When the program is run, the following output is displayed:
This is a simple Java program

When Java source code is compiled, each individual class is put into its own output file named after the class and using the .class extension. When you execute the Java interpreter as just shown, you are actually specifying the name of the class that you want the interpreter to execute. It will automatically search for a file by that name that has the .class extension. If it finds the file, it will execute the code contained in the specified class.

Friday 8 June 2012

Java's Magic: The Bytecode

The key that allows Java to solve both the security and the portability problems is that the output of a Java compiler is not executable code. Rather, it is bytecode. Bytecode is a set of instructions designed to be executed by the Java run-time system known as Java Virtual Machine (JVM). That is, in its standard form, the JVM is an interpreter for bytecode. 
Translating a Java program into bytecode helps makes it easier to run a program in a wide variety of environments. The reason is straightforward: only the JVM needs to be implemented for each platform. Once the run-time package exists for a given system, any Java program can run on it. Although the details of JVM will differ from platform to platform, all interpret the same Java bytecode. 
The fact that a Java program is interpreted also helps to make it secure. Because the execution of every Java program is under the control of the JVM, the JVM can contain the program and prevent it from generating side effects outside of the system. 
Although Java was designed for interpretation, there is technically nothing about Java that prevents on-the-fly compilation of bytecode into native code. Along these lines, Sun supplies its Just In Time (JIT) compiler for bytecode, which is included in the Java 2 release. When JIT compiler is part of the JVM, it compiles bytecode into the executable code in real time, on a piece-by-piece, demand basis. It is not possible to compile an entire Java program into executable code all at once, because Java performs various run time checks that can be done only at run time. Instead, the JIT compiles code as it is needed, during execution.

The Creation of Java

Java was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems, Inc. in 1991. It took 18 months to develop the first working version. This language was initially called "Oak" but was renamed "Java" in 1995. The primary motivation was the need for platform-independent (that is architecture neutral) language that could be used to create software to be embedded in various consumer electronic devices, such as microwave ovens and remote controls. As you can probably guess, many different types of CPUs are used as controllers. The trouble with C and C++ is that they are designed to be compiled for a specific target. Although it is possible to compile a C++ program for just about any type of CPU, to do so requires a full C++ compiler targeted for that CPU. The problem is that compilers are expensive and time-consuming to create. In an attempt to find such a solution, Gosling and others began work on a portable, platform-independent language that could be used to produce code that would run on a variety of CPUs under differing environments. This effort ultimately led to the creation of Java. Java derives much of its characters from C and C++. This is by intent. 

Thursday 7 June 2012

Signed Binary Numbers: Two's Complement Representation

If 1 is added to 1's complement of a binary number, the resulting number is known as the two's complement of the binary number. For example, 2's complement of 0101 is 1011. Since 0101 represents (+5)10, therefore, 1011 represents (-5)10 in 2's complement representation. In this representation also, if the MSB is 0 the number is positive, whereas if the MSB is 1 the number is negative.

Exercise
Find the 2's complement of the numbers
  1. 01001110
Solution:

    0 1 0 0 1 1 1 0................Number   

    1 0 1 1 0 0 0 1................1's complement          

                         1................Add 1  
    1 0 1 1 0 0 1 0

From the above example, we observe the following:
  1. If the LSB of the number is 1, its 2's complement is obtained by changing each 0 to 1 and 1 to 0 except the least-significant bit.
  2. If the LSB of the number is 0, its 2's complement is obtained by scanning the number from LSB to MSB bit by bit and retaining the bits as they are up to and including the occurrence of the first 1 and complement all other bits. 

Signed Binary Numbers: One's Complement Representation

In a binary number, if each 1 is replaced by 0 and each 0 by 1, the resulting number is known as the one's complement of the first number. In fact, both the numbers are complement of each other. If one of these numbers is positive, then the other number will be negative with the same magnitude. For example, (0101)2 represents (+5)10, whereas (1010)2 represents (-5)10 in this representation. This method is widely used for representing signed numbers. In this representation also, MSB is 0 for positive numbers and 1 for negative numbers. 

Exercise 1
Find the one's complement of the following binary numbers.

  1. 0100111001
  2. 11011010
Solution:

1) 1011000110
2) 00100101

Exercise 2
Represent the following numbers in one's complement form.
  1. +7 and -7
  2. +8 and -8
  3. +15 and -15
Solution:

1) (+7)10 = (0111)2 and (-7)10 = (1000)2
2) (+8)10 = (01000)2 and (-8)10 = (10111)2
3) (+15)10 = (01111)2 and (-15)10 = (10000)2


Wednesday 6 June 2012

Signed Binary Numbers: Sign-Magnitude Representation

In the decimal number system a plus (+) sign is used to denote a positive number and a minus (-) sign is used to denote a negative number. The plus sign is usually dropped, and the absence of any sign means that the number has positive value. This representation of numbers is known as signed number. Digital circuits can understand only two symbols, 0 and 1; therefore we must use the same symbols to indicate the sign of the number also. Normally, an additional bit is used as the sign bit and it is placed as the most significant bit. A 0 is used to represent a positive number and a 1 to represent a negative number. For example, an 8-bit signed number 01000100 represents a positive number and its value (magnitude) is (1000100)2 = (68)10. The left most 0 (MSB) indicates that the number is positive. On the other hand, in the signed binary form, 11000100 represents a negative number with magnitude (1000100)2 = (68)10. The 1 in the left most position (MSB) indicates that the number is negative and the other seven bits give its magnitude. This kind of representation for signed numbers is known as sign-magnitude representation. The user must take care to see the representation used while dealing with binary numbers.

Exercise
Find the decimal equivalent of the following binary numbers assuming sign-magnitude representation of the binary numbers.

  1. 101100
  2. 001000
  3. 0111
  4. 1111
Solution:

1) Sign bit is 1, which means the number is negative.
     Magnitude = 01100 = (12)10
      (101100)2 = (-12)10

2) Sign bit is 0, which means the number is positive.
    Magnitude = 01000 = 8
    (001000)2 = (+8)10

3) (0111)2 = (+7)10

4) (1111)2 = (-7)10

Binary Addition

The rules of binary addition are given in following table








In the first three rows above, there is no carry, that is, carry = 0, whereas in the fourth row a carry is produced (since the largest digit possible is 1), that is, carry = 1, and similar to decimal addition it is added to next higher binary position.

Example 
1) Add 1011 and 1100

Solution


             1      0      1      1
  (+)      1      1      0      0
     1      0      1      1      1
Carry






Following figure shows Binary addition along with its equivalent decimal addition.


From the above example, we observe the following:
  1. if the number of 1's to be added in a column is even then sum bit is 0, and if number of 1's to be added in a column is odd then the sum bit is 1.
  2. Every pair of 1's in a column produces a carry (1) to be added to the next higher bit column. 

Binary to Decimal and Decimal to Binary Conversion


Binary to Decimal conversion
Any binary number can be converted into its equivalent decimal number using the weights assigned to each bit position.

Decimal to Binary conversion
Any decimal number can be converted into its equivalent binary number. For integers, the conversions is obtained by continuous division by 2 and keeping track of the remainders, while for fractional parts, the conversion is affected by continuous multiplication by 2 and keeping track of the integers generated. The conversion process is illustrated by the following examples.


Binary Number System



The number system with base (or radix) two is known as the binary number system. Only two symbols are used to represent numbers in this system and these are 0 and 1. These are known as bits. This system has the minimum base (0 is not possible and 1 is not useful). It is a positioned system, that is every position is assigned a specific weight.
The following table illustrates counting in binary number system. The corresponding decimal numbers are given in the right hand column. Similar to decimal number system, the left-most bit is known as the most significant bit (MSB) and the right-most bit is known as the least significant bit (LSB). Any number of 0s can be added to the left of the number without changing the value of the number. In the binary number system, a group of four bits is known as nibble, and a group of eight bits is known as a byte

4-bit binary numbers and their corresponding decimal numbers

      Binary number                                      Decimal number    

 0         0        0        0                                       0         0
 0         0        0        1                                       0         1
 0         0        1        0                                       0         2
 0         0        1        1                                       0         3
 0         1        0        0                                       0         4  
 0         1        0        1                                       0         5
 0         1        1        0                                       0         6
 0         1        1        1                                       0         7 
 1         0        0        0                                       0         8
 1         0        0        1                                       0         9
 1         0        1        0                                       1         0
 1         0        1        1                                       1         1
 1         1        0        0                                       1         2
 1         1        0        1                                       1         3
 1         1        1        0                                       1         4 
 1         1        1        1                                       1         5

Sunday 3 June 2012

Boolean Algebra

The digital signals are discrete in nature and can only assume one of the two values 0 or 1. A number system based on these two digits is known as binary number system. In the middle of 19th century, an English mathematician George Boole developed rules for manipulations of binary variables, known as Boolean Algebra. This is the basis of all digital systems like computers, calculators, etc.

Binary variables can be represented by a letter symbol such as A, B, X, Y, ... The variable can have only one of the two possible values at any time, viz. 0 or 1. The Boolean algebraic theorems are shown in following table. 



Theorem No. Theorem
1) A + 0 = A
2) A . 1 = A
3) A + 1 = 1
4) A . 0 = 0
5) A + A = A
6) A . A = A
7) A + ~A = 1
8) A . ~A = 0
9) A . (B + C) = AB + AC
10) A + BC = (A + B) (A + C)
11) A + AB = A
12) A(A + B) = A
13) A + ~AB = (A + B)
14) A(~A + B) = AB
15) AB + A~B = A
16) (A + B). (A + ~B) = A
17) AB + ~AC = (A + C) (~A + B)
18) (A + B)(~A + C) = AC + ~AB
19) AB + ~AC + BC = AB + ~AC
20) (A + B)(~A + C)(B + C) = (A + B)(~A + C)
21) ~(A . B . C...) = ~A + ~B + ~C + ...
22) ~(A + B + C...) = ~A . ~B . ~C...

Theorems 1 to 8 involve a single variable only. Each of these theorems can be proved by considering every possible value of the variable. For example, in theorem 1,
if A = 0 then 0 + 0 = 0 = A
and if A = 1 then 1 + 0 = 1 = A
and hence the theorem is proved.

Theorems 9 to 20 involve more than one variable and can be proved by making a truth table. For example, Theorem 10 can be proved by making the truth table given below.

Truth table to prove Theorem 10

   A     B     C     BC     A + BC     A + B      A + C      (A+B) (A+C)   
0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0
0 1 1 1 1 1 1 1
1 0 0 0 1 1 1 1
1 0 1 0 1 1 1 1
1 1 0 0 1 1 1 1
1 1 1 1 1 1 1 1

For each combination, the value of A + BC is same as that of (A+B) (A+C), which proves the theorem.
Theorem 21 and 22 are known as De Morgan's theorems.

Exclusive-OR Operation

The Exclusive-OR (EX-OR) operation is widely used in digital circuits. It is not a basic operation and can be performed using the basic gates- AND, OR and NOT or universal gates NAND or NOR. Because of its importance, the standard symbol shown below is used for this operation.


Logical equation of EX-OR gate is written as

Y = A EX-OR B

From the truth table we observe that when both inputs are same (0 or 1) the output is 0, whereas when the inputs are not same (one of them is 0 and the other one is 1) the output is 1.

Thursday 31 May 2012

The NOR Operation

The NOT-OR operation is known as the NOR operation. The following figure shows 2-input OR gate followed by a NOT gate. The standard symbol of the NOR gate is shown in following diagram. A bubble on the output side of the NOR gate represents the NOT operation.


The operation of this circuit can be described in the following way:

The output of the OR gate Y' can be written as

Y' = A + B + ... + N

and the output of the NOT gate (Y) can be written as
       _      ____________
Y = Y' = A + B + ... + N

The logic operation represented by above equation is known as NOR operation.

The three basic logic operations, AND, OR and NOT can be performed by using only the NOR gates. These are shown in following diagram.




The NAND Operation

The NOT-AND operation is known as the NAND operation. Following figure shows two input NAND gate.
The standard symbol of NAND gate is shown in following diagram. Here, a bubble on the output side of the NAND gate represents NOT operation, inversion.


Figure shows 2-input AND gate followed by a NOT gate. The operation of this circuit can be described in the following way:

The output of the AND gate (Y') can be written as
        
Y' = AB .. N

Now, the output of the NOT gate (Y) can be written as
       _     ________
Y = Y' = (AB ... N)            
The logical operation represented by above equation is known as the NAND operation. 

The three basic logic operations AND, OR and NOT can be performed by using only NAND gates. These are given in following figure.





Basic Digital Circuits

In a digital system there are only a few basic operations performed, irrespective of the complexities of the system. The basic operations are
1) AND
2) OR
3) NOT

The AND, OR and NOT operations are discussed here

1) The AND Operation


A circuit which performs an AND operation is shown in following figure. It has 2 inputs and one output.


Digital signals are applied at the input terminals marked A and B, the output is obtained at output terminal marked 'Output' and it is also a digital signal. The AND operation is defined as : the output of AND gate is 1 if and only if all the inputs are 1. Mathematically, it is written as

Y = A AND B AND C......AND N
    = A * B *  C * ..... * N                                                                                                  (1)

where A,B,C,.....N are the input variables and Y is the output variable. The variables are binary, i.e. each variable can assume only one of the two possible values, 0 or 1. The binary variables are also known as logical variables.
Equation (1) is known as the Boolean equation or the logical equation of AND gate. The term gate is used because of the similarity between the operation of a digital circuit and a gate. For example, for an AND operation the gate opens (Y=1) only when all the inputs are present, i.e. at logic 1 level.

2) The OR Operation


Following figure shows an OR gate with 2 inputs and one output.


The OR operation is defined as : the output of an OR gate is 1 if and only if one or more inputs are 1. Its logical equation is given by

Y = A or B or C......OR N
    = A + B + C + ...+ N                                                                                          

3) The NOT Operation


Following figure shows a NOT gate, which is also known as inverter. It has one input and one output.

Its logical equation is given by

Y = NOT A
    = A'


Thursday 24 May 2012

Digital Signals

A digital signal has two discrete levels or values. These levels can be represented using the terms ON(HIGH) and OFF(LOW). The two discrete signal levels ON and OFF can also be represented by the binary digits 1 and 0 respectively. A binary digit (0 or 1) is referred to as a bit. Since a digital signal can have only one of the two possible values 1 or 0, the binary number system can be used for the analysis and design of digital systems.

Digital signal

The two levels also be designated as TRUE and FALSE. George Boole introduced the concept of binary number system in the studies of mathematical theory of LOGIC in the work entitled. An 'Investigation of the Laws of Thought' in 1854 and developed its algebra known as Boolean algebra.
These logic concepts have been adapted for the design of digital hardware since 1938 when Claude Shannon-organised and systematized Boole's work in Symbolic Analysis of Relay and Switching Circuits.

Fundamental concepts of Digital Electronics

All of us are familiar with the impact of modern digital computers, communication systems, digital display systems, internet, email, etc. on society. One of the main causes of this revolution is the advent of integrated circuits (ICs), which became possible because of the tremendous progress in semiconductor technology in recent years. The operation of computers, communication systems, internet, email, etc., and many other systems, is based on the principles of digital techniques and these systems are referred to as digital systems.
Some of us are familiar with electronic amplifiers. These are used to amplify electrical signals. This type of signals are continuous signals and can have any value in a limited range and are known as analog signals. The electronic circuits used to process these signals are known as analog circuits and the systems built around this kind of operation are known as analog systems.

On the other hand, in an electronic calculator, the input is given with the help of switches. This is converted into electrical signals having two discrete values or levels. One of these known as LOW level and the other as HIGH level. This type of signal is known as digital signal and the circuits inside the calculator used to process these signals are known as digital circuits. A calculator is an example of a digital system.

Tuesday 22 May 2012

What is Information Technology?

Information Technology is a field that deals with use of computers to store, retrieve, process and transmit information. In simple words, we can say that information is nothing but processed data. Information is a sequence of symbols that can be interpreted as message. Information can be recorded as signs, or transmitted as signals. Technology deals with a wide variety of areas that include computer software, computer hardware, information systems, programming languages. In short we can say that "Information Technology " uses technology to handle information.