Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Thu, 14 Mar 2024 16:53:13 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg Programmerbay https://programmerbay.com 32 32 What Are the Five Main Features of OOPs? https://programmerbay.com/what-are-the-five-main-features-of-oops/ https://programmerbay.com/what-are-the-five-main-features-of-oops/#respond Wed, 13 Mar 2024 16:28:49 +0000 https://programmerbay.com/?p=5082 Object-Oriented Programming or OOPs is a programming paradigm that revolves around the concept of object, which contains properties and methods. 
It combines a group of related attributes and behaviour within a single unit named class, that enhances program design structure and code readability.
Further, it also resolves drawbacks of Procedural programming i.e  code complexity, unusable code.
 
Problem with Procedural Programming?
Procedural Programming follows top-down approach, meaning a program is viewed as a series of sequential steps.
In procedural programming, a program is divided into various procedures or functions which operate on data, the issue with this approach is, when the program grows larger, the code redundancy, maintainability, and complexity increases.
 
Both procedural and object-oriented are imperative programming.
 

Feature of OOPs

 
Object-Oriented programming focuses on binding attributes and behavior of a real-world entity represented using an object and supports features like abstraction, encapsulation, inheritance, and polymorphism. These are the following OOPs features.
  • Classes
  • Objects
  • Inheritance
  • Polymorphism
  • Data Abstraction and Encapsulation

Other OOPs Features:

  • Dynamic Binding
  • Message Passing

Here are the five main features of OOPs

Classes:

A class is the user-defined data type and the main building block of object-oriented programming.
It is an identifiable entity that can have some descriptive properties. It is a user-defined data type that holds data members and member functions in a single unit. It is like a blueprint of an object.
 
For example, consider an entity “Laptop” , what attributes, you can think of? RAM, OS, memory, manufacturer name, model name and so on.
 
public class Laptop
{
String modelName;
String manufacturerName;
String ram;
String memory;
String os;


void boot(){


}
}

The above code represents, how a laptop’s attributes and its behavior are put together in a single place.

Objects:

Objects are like a signature of a class. An object is an instance of a class without an object, no memory is allocated to a class’s data members or member function.
With an object of a class, we can access the data members and member functions that can be accessed (as per the private, public, protected accessibility scope).
 
An object represents a real-world entity, having a set of attributes and behavior. However, an object can’t be simply declared as same as primitive types.
 
Continuing Laptop’s example, we can define multiple Laptop objects and each object would get the same attributes and behavior declared in the respective class.
Laptop obj = new Laptop();
Laptop obj1 = new Laptop();
Laptop obj2 = new Laptop();

Initializing fields of a single object .

obj.modelName = " Pavilion 15";
obj.manufacturerName = "HP";
obj.ram = "4 GB";
obj.memory = "1 TB";
obj.os = "Windows";

Inheritance:

The ability to inherit the properties of one class to another, or inherit the properties from a base class to an inherited class is known as the concept of Inheritance.
With the help of inheritance, we can use the data members and member functions of a class to another.
 
  • It enables a class to acquire or get the properties from another class
  • It makes code reusable
  • It makes easier to add new features or methods to a class
  • It provides an overriding feature which allows a child class to have a specific implementation of a method defined in the parent class
 
A class that is inherited by other classes is termed as super class or parent class or base class, whereas a class that extends another class is termed as sub-class or child class
 
Features of Inheritance :
  • Code Reusability
  • Ease to add new feature
  • Overriding
 
Inheritance can be classified into majorly 5 types : Single Inheritance, Multilevel inheritance, Hierarchical Inheritance, Multiple Inheritance and Hybrid Inheritance
 
Syntax :
class Laptop extends Electronics
{


}

We can also control or check the data members and member functions to be accessed in the child classes by the means of access specifiers, types of inheritance, access specifiers, and their respective access will be discussed in later articles.

Polymorphism:

Polymorphism is best defined in one statement i.e., “Polymorphism means one name many forms”.
 
It can be best explained with an example with a comparison to C language; in C language there was one limitation that we can not use the already used function name, but C++ provides us a new feature of Polymorphism, by which we can use the same function name again and again with different signatures.
 
 
The in-depth topic of Polymorphism will be discussed in later articles.

Data Abstraction and Encapsulation:

 
Data Abstraction means hiding the background details and provide only essential details. one of the most common examples regarding this feature is Television, in television we control it with help of a remote and, know its external or the features to be used most whereas we don’t know the internal working of Television.
 
 
Encapsulation means binding up data under a single unit. A class is one of the main implementations of this concept. It can be viewed as a wrapper that restricts or prevents properties and methods from outside access. With the help of access modifiers such as private, protected, and public keywords, one can control the access of data members and member functions

Other OOPs Features:

Dynamic Binding:

Dynamic Binding which is also known as Late binding or run-time binding, is a process of executing the part of the code at runtime.
Sometimes we need to access some part at the runtime if we need then we can use this approach. We use virtual functions to achieve Dynamic Binding.

Message Passing:

In this, objects pass the message to each other in order to contact each other. Like when we want 2 or multiple objects to contact each other it is possible with the OOP.
 

Frequently Asked Questions

 

Q1. What is an object in OOPs?

An object can be viewed as a real-world entity which has attributes and behaviour. For example, a person, it can have attributes like name, age, gender and behaviour such as talking and walking. These properties are put together within a single unit named class. Therefore, an instance of a class is known as an object.

Q2. Which feature of oops is described as the reusability of code?

Inheritance is the feature of OOPs that describes the reusability of code. It provides the ability to inherit attributes and behaviours from one class to another class. A child class can access and use methods and fields of the parent class which leads to code reusability.


Q3. Which feature of oop is illustrated by function overloading?

Polymorphism is the feature of OOPs that is illustrated by function overloading or method overloading. Method overloading signifies a method having the same name can exhibit multiple functionalities based on its parameters.


Q4. Which two features of oops are the same?

Encapsulation and Abstraction are two features of OOPs that are the same. Encapsulation can manage accessibility and hide the attributes and behaviour of an object. In same way,  Abstraction represents only essential data to a user.


Q5. What are the basic principles of OOPs?

Encapsulation, Data Abstraction, Polymorphism and Inheritance are 4 basic principles of Object-Oriented Programming. They are also known as the four pillars of OOPs.

 

]]>
https://programmerbay.com/what-are-the-five-main-features-of-oops/feed/ 0
Counting Figures Tricks with Triangle Examples https://programmerbay.com/counting-figures-problem-tricks/ https://programmerbay.com/counting-figures-problem-tricks/#respond Tue, 12 Mar 2024 06:09:49 +0000 https://www.programmerbay.com/?p=4385 Counting figures problems come under non-verbal reasoning in which one is required to identify the exact count of a shape formed within a design or picture like a circle, square, triangle and more. Such type of logical reasoning questions are frequently asked in different aptitude exams.

Counting figures sometimes sound too difficult if you don’t have an idea of how to solve them. In this article, we will be talking about tricks for counting figures problem.

counting figures

These are most repeatedly asked reasoning questions. In this, a shape or a figure would be given to you and your task is to determine the shape and count it down within that particular shape.
For example, consider the below figure:

countinng figure 4

They simply ask in the question, how many triangles are visible in the given figure? Initially, it might look easy but it is obviously not! Without knowing tricks you can’t easily figure out correct answer.

 

Types of questions with Triangle Counting Problem Examples

  • When a triangle  is divided  by  vertical lines

    • In such a case, we use can n (n+1)/2 where n is the number of triangles inside the main triangle

Q.  Find the number of triangles in the diagram

counting figures 1

Number of  triangles  inside the  main triangle   =   4

4(4+1)/2

= 20/2    =    10

 

  •  When a  triangle divided  by the horizontal lines

    • In such a case, count the number of horizontal lines that would give you the total number of triangles

Q.  Find the number  of figures  in the diagram

counting figure 2

Total number of horizontal lines = 3

So total possible triangles are 3

 

  • When a triangle has both vertical and horizontal lines

    • n(n+2)/2 (for vertical lines ) * number of horizontal lines

Q.  Find the number  of triangles in the diagram

counting figures 3

Number of triangles from vertical lines (ignoring horizontal lines) = 3 = 3(3+1)/2 = 6

Horizontal lines  = 3

= 6* 3

= 18

 

  • When a triangle has an inner triangle touching all of the edges of the outer one

    • In such a case, there always 4 figures are made and add 1 for the main triangle

Q.  Find the number  of triangles in the diagram

countinng figure 4

Starting from inner combination there are  = 4 triangle

count me

outer combination there are  = 4 triangle

count me 1

And for main  = 1

total = 9 triangles

 

  • When a triangle has a triangle touching all of the edges of outer one and also has lines from each vertex of the main triangle touching edges of the inner one

    • In this first, ignore all the lines coming from corners of the triangle
    • Now the triangle you see would  be similar to the previous case triangle ( touching all the edges of outer triangle)
    • Count the number of triangles
    • After that consider lines coming from edges, each line would make 2 triangles
    • Now add them all together

counting figure 5

Step 1.  If we ignore the lines coming from edges, the figure would look like

countinng figure 4

Step 2.  From the inner triangle, we will get 4, from outer one = 4, Main triangle = 1

Step 3. Total triangles = 9

Step 4. Now add lines which were removed previously, if each line creates 2 triangles then 3 lines would create = 3*2 =6 triangle

Step 5. Add them all. 9 + 6 = 15 triangles

 

  •  When a triangle has multiple triangles made on horizontal lines 

    • If you look closely from every edge there would equal number of triangles
    • Count triangles from the base
    • Add them in a consecutive manner where the result of the previous one would be used as input for the next one. i.e 1 , 1 +2 = 3, 3+3=6, 4+6 =10′. Add all the sums together.
    • Now after adding them all up, also consider second last sum again
    • Also add it

counting figure 6

Number triangles in each base = 3

Make a counting from 1 to 3

count me 3

Add them up = 1 + 3 + 6 = 10

Now also consider second last item = 3

Total triangle 10 + 3 = 13

 

Counting Figures Practice Questions

 

1. How many triangles are there in the given figure?

Screenshot from 2024 03 14 22 03 30

2. How many triangles are there in the given figure?

Screenshot from 2024 03 14 22 04 34

3.  Find the number of triangles in the given figure :

Screenshot from 2024 03 14 22 08 35

Frequently Asked Questions:

What is the Figure Counting Reasoning?

It comes under non verbal reasoning section where one requires to identify and count the exact number of shapes present in the given figure or design.

]]>
https://programmerbay.com/counting-figures-problem-tricks/feed/ 0
Difference between While and Do While loop in Tabular Form https://programmerbay.com/difference-between-while-and-do-while-loop/ https://programmerbay.com/difference-between-while-and-do-while-loop/#respond Mon, 11 Mar 2024 16:17:31 +0000 https://programmerbay.com/?p=6343 In this article we’ll be discussing the difference between while and do while loop and how they work.

Control statements provide an ability to execute a particular set of statements in a controlled manner. Basically, these statements are powerful statements that can mange the flow of a program.

Every programming language supports a basic form of Iteration statements that are known as loops, for example, While, Do-While and For loop.

 

While and do while loop

Iteration statements are categorised as the control statements. It allows us to iterate through a piece of code repeatedly.

The goal of all looping statements is to run a particular block of statements frequently until a specific condition is met. However, Do-While and While loop follows a completely different approach to looping around a statement. Both types of loops are different from each other when it comes to their order of execution and condition evaluation.

What is a loop?

A loop can be defined as a control statement that enables repetitive execution of a block of code until a given condition turns out to be false. It provides capability to write a block of code and execute it repeatedly for specific number of times. Suppose, if a block of code needs to be executed repeatedly, in such case, we must use loops, instead of writing the same code multiple times.

Normally a looping statement comprises of following components:

  • Control or counter variable initialization
  • Condition evaluation
  • Loop body execution
  • Counter variable updation

There are primarily three types of loops  :
1) while loop
2) do while loop
3) for loop

The main difference between While and Do-While loop is that one evaluates condition first and then executes the loop body, whereas, other one executes the loop body first and then checks for the condition.

Difference between While and Do While Loop in Tabular form

BasisWhile LoopDo-While Loop
DefinitionIn this, the given condition is evaluated first, and then loop body is executedIn this, the given loop body is executed first and then after the given condition is checked
Loop TypeIt is an entry-controlled loopIt is an exit-controlled loop
Loop ExecutionThe loop body would be executed, only if the given condition is trueThe loop body would be executed at least once, even if the given condition is evaluated as false
Counter Variable Intialization It allows initialization of counter variable before entering loop bodyIt allows initialization of counter variable before and after entering loop body
SemicolonNo semicolon is used as a part of syntax,
while(condition)
Semi-colon is used as a part of syntax,

while(condition);
UsageIt is used when condition evaluation is required to be evaluated first, before executing loop bodyDo-While is used when one needs to enter into the loop body before evaluating condition. For example, Menu driven programs
SyntaxSyntax:

while( condition )
{
// loop body
}
do
{
// loop body
}while( condition );

While Loop

While Loop can be defined as the loop where the condition is evaluated first and then after the loop body is executed. It is an entry controlled loop.

Syntax:

while(condition)
{
// body
}

How while loop works?

  • Counter or control variable initialization
  • Then, condition would be checked
  • If it is evaluated as true, then
  • loop body would be executed
  • Otherwise, the loop gets terminated

Entry Controlled Loop

A Program example for While loop:

Example 1. C program to demonstrate working of while loop

Program

#include <stdio.h>

int main ()
{

  int i = 1;
  while (i < 5)
    {
      printf ("Print :: %d \n", i);
      i++;
    }
  return 0;
}

Output:

Print :: 1 
Print :: 2 
Print :: 3 
Print :: 4 

Explanation:

In the above example, we are simply initializing counter variable i with 1. And iterating using while loop until the condition  having i is less than 5 becomes false. In loop body, we are printing a message and incrementing counter variable on very next line.

Example 2. C program to show the approach difference of while loop with do-while

#include<stdio.h>
void main()
{
int i=10;
while(i<10)
{
printf("I will not be executed as it is entry controlled loop");
i++;
}
getch();
}

Explanation:

Since, condition would be evaluated as false at very first place , no output would be printed. In this, counter variable ‘i’ was holding value 10. And at the entry point of while loop, when condition got evaluated for ‘i< 10’, it turned out to be false. As a result, the loop terminated.

Do-While Loop

Completely opposite to While loop, Do-While is a looping statement in which condition is checked after the execution of the loop body. It is a type of exit controlled loop.

Syntax:

do
{
// loop body

}whie(condition);

How do-While works?

  • Counter or control variable initialization
  • Loop body gets executed first and then-after the condition is evaluated
  • If the condition is evaluated as true, then loop would proceed to next iteration
  • Otherwise, it gets terminated

Exit Controlled Loop

A  Program example of Do-While loop

Example 1. C program to demonstrate working of do while loop

Program:

#include <stdio.h>

int main ()
{
  int i = 1;
  do
    {
      printf ("Print :: %d \n", i);
      i++;
    }while (i < 5);
  return 0;
}

Output:

Print :: 1 
Print :: 2 
Print :: 3 
Print :: 4 

Explanation:

In the above example, we are initializing counter variable i with 1. And iterating using do while loop until i is less than 5. In loop body, we are printing a message and incrementing counter variable on very next line. Lastly, we’re checking the condition and iterate accordingly.

Example 2. C program to show the approach difference of do-while loop with while

#include<stdio.h>
void main()
{
  int i=10;
  do
  {
  printf("I will be executed at once as it is exit controlled loop");
  i++;
  }while(i<10);
  getch();
}

Explanation:

Print statement would be executed at once, even though the condition is false. In this, counter variable ‘i’ was 10. In this, the loop body got executed first which resulted in print statement execution. And lastly, condition got evaluated for ‘i< 10’, it turned out to be false. As a result, the loop terminated.

Exit Controlled and Entry Controlled Loop

A loop that executes the loop body first and then checks for a condition is known as an exit controlled loop. For example Do-While loop.

On the other hand, a loop that checks for condition first and run the loop body can be categorized as entry controlled loop. For example, While loop, and For loop.

]]>
https://programmerbay.com/difference-between-while-and-do-while-loop/feed/ 0
C Program to Sort an array using Selection Sort in Ascending Order https://programmerbay.com/program-to-sort-an-array-using-selection-sort/ https://programmerbay.com/program-to-sort-an-array-using-selection-sort/#respond Sun, 03 Mar 2024 17:20:38 +0000 https://www.programmerbay.com/?p=2879 The program sorts uses Selection Sort technique to sort the given array. There are bunch of sorting mechanisms such as Bubble sort, Insertion sort and more to achieve this functionality. In this, we’ll be only focusing Selection Sort .

Selection Sort

Selection sort is a sorting technique wherein at each iteration, a minimum element is selected from an unsorted array and compared with all other remaining elements. if an element is found that is smaller than already assumed minimum element,  swapping would be performed.

It divides an array into two parts. One that is already sorted and another one which is still unsorted that need to be arranged.

From unsorted sublist, the algorithm finds the minimum element and adds on to sorted category. It ends when we get a single consolidated sorted sublist.

Pseudocode

FOR i=0 to Array.Length
minimum = i
FOR j=0 to Array.Length
if A[min]< A[j])
Swap A[min] with A[j]
End IF
END FOR
END FOR

C program to sort an array using Selection Sort in Ascending Order

#include<conio.h>
#include<stdio.h>
#define size 5
void main()
{
int arr[size],i,j,temp,min;
printf("Please enter elements: \n "); 
for(i=0;i<=size-1;i++)
{
scanf("%d",&arr[i]);
}

for(i=0;i<=size-1;i++)
{
min= i;
for(j=0;j<=size-1;j++)
{
if(arr[min]<arr[j]){
temp = arr[j];
arr[j] =arr[min];
arr[min] = temp;
}
}
}

printf(" \n Entered Elements :");

for(i=0;i<=size-1;i++)
{
printf("\n %d ",arr[i]);
} 
getch();

}

Output:

Screenshot from 2024 03 10 22 22 03

 

How does Selection Sort work?

Screenshot from 2024 03 10 22 28 33

 

Lastly, it is an inefficient algorithm for the large dataset as it requires O(n2) comparisons in all cases worst, average and best case. It is simple and occasionally has an upper hand over other complicated algorithms.

]]>
https://programmerbay.com/program-to-sort-an-array-using-selection-sort/feed/ 0
Design 2 bit synchronous up down counter using T flip flop? https://programmerbay.com/design-2-bit-synchronous-up-down-counter-using-t-flip-flop/ https://programmerbay.com/design-2-bit-synchronous-up-down-counter-using-t-flip-flop/#respond Fri, 01 Mar 2024 17:29:00 +0000 http://programmerbay.com/?p=3111

These are the following steps to design 2 bit synchronous up down counter using T flip flop:

Step 1: To design a synchronous up-down counter, we need one extra input called control input. Other than this, in next state column, half of the input must be appeared as up counter and the remaining must be treated as a down counter.

Step 2: After that, we need to construct a state table with excitation table.

Note: To construct excitation table from state table you should know the excitation table of respective flip flop, in this case, it is T flip flop. So check the excitation table for T flip flop Which is:

T Flip Flop Excitation Table

Present stateNext State    T
000
011
101
110

So, the above table is the excitation table for T Flip Flop.


State Table with  excitation  table

   Control input   Present State    Next State    Flip Flop
CiQ2Q1Q'2Q'1T2T1
0000101
0011011
0101101
0110011
1001111
1010001
1100111
1111001

Above the table is created as per follow :

When Q2 =0 which is the present state and Q2‘=0 which is next state then T2 become 0 [As per excitation table, have a look ]
Similarly, if Q2 is 0 and Q2‘ is 1 then T2 becomes 1.
In a similar way, it goes on .

Step 3: After making the excitation table the next thing  to do is dig out the equation from the boolean algebra or K map for the design of the counter. So, for T1 and  T2we got 1, and Q1‘.Ci + Q1.Ci’

K-Map

 

 

For T2  Flip flop,

2 2Bbit 2Bup 2Bdown1

 

T2= Q1‘.Ci + Q1.Ci’

For TFlip flop,

2 2Bbit 2Bup 2Bdown2

 

T1=1

Step 4: Lastly according to the equation got from K map create the design for 2 bit synchronous up down counter.

 

2 2Bbit 2Bup 2Bdown

Related posts:

Design a 2 bit Synchronous down counter using T Flip flop?
Design a 2 bit Synchronous up counter using T Flip flop? 

]]>
https://programmerbay.com/design-2-bit-synchronous-up-down-counter-using-t-flip-flop/feed/ 0
Design a 2 bit Synchronous down counter using T Flip flop? https://programmerbay.com/design-a-2-bit-synchronous-down-counter-using-t-flip-flop/ https://programmerbay.com/design-a-2-bit-synchronous-down-counter-using-t-flip-flop/#respond Fri, 01 Mar 2024 15:03:00 +0000 http://programmerbay.com/?p=3112

These are the following steps to design a 2 bit synchronous down counter using T Flip flop:

Step 1: To design synchronous down counter, we just require to change the order of present state and next state, just put 0 where is 1 in synchronous up counter. In other words, start from 11 (3) to 00 (0)

Step 2: After that, we need to construct a state table with excitation table.
Note: To construct excitation table from state table you should know the excitation table of respective flip flop, in this case, it is T flip flop. So check the excitation table forT flip flop Which is:

T Flip Flop Excitation Table

Present stateNext State    T
000
011
101
110

So, the above table is the excitation table for T Flip Flop.


State Table with  excitation  table

   Present State    Next State    Flip Flop
Q2Q1Q'2Q'1T2T1
001111
010001
100111
111001

Above the table is created as per follow :

When Q2 =1 which is present state and Q2‘=1 which is next state then T2 become 0 [As per excitation table, have a look ]
Similarly, if Q2 is 1and Q2‘ is 0 then T2 becomes 1.
In a similar way, it goes on.

Step 3: After making the excitation table the next thing to do is dig out the equation from the boolean algebra or K map for the design of the counter. So For T1 and T2 we got 1 and Q1‘ .

K-Map

 

For T2  Flip flop,

 

2 2BBIT 2BDown

 

 

 

T2= Q1

For TFlip flop,

Q2

 

T1=1

Step 4: Lastly according to the equation got from K map create the design for 2 bit synchronous down counter.

2 2BBIT 2BDown 2Bdesign

In above design T1 is getting high input  and T2 is getting input from the output of the T1 which is complement of the output.  A clock is attached to it which is always high in blue color.

Popular Posts:

Design a 2 bit Synchronous up counter using T Flip flop?

 

]]>
https://programmerbay.com/design-a-2-bit-synchronous-down-counter-using-t-flip-flop/feed/ 0
C Program to Draw a Hut https://programmerbay.com/c-program-to-draw-a-hut/ https://programmerbay.com/c-program-to-draw-a-hut/#respond Thu, 29 Feb 2024 17:23:26 +0000 https://www.programmerbay.com/?p=1886 C supports a header file named “graphics.h” which enables us to draw various figures. In this, we’ll be using line and rectangle function of that particular header file to draw a hut.

C Program to draw a hut in computer graphics

Program:

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main(){
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\t\t ********* HUT ********");
line(150,100,50,200);
line(150,100,350,100); 
line(150,100,300,200);
line(300,200,500,200);
line(350,100,500,200);
line(50,200,300,200);
rectangle(50,400,300,200);
rectangle(300,200,500,400);
rectangle(130,250,230,400);

getch();
closegraph();

}

Output:

Hut

]]>
https://programmerbay.com/c-program-to-draw-a-hut/feed/ 0
Design 2 bit Synchronous up counter using T Flip flop? https://programmerbay.com/design-a-2-bit-synchronous-up-counter-using-t-flip-flop/ https://programmerbay.com/design-a-2-bit-synchronous-up-counter-using-t-flip-flop/#respond Thu, 29 Feb 2024 16:35:00 +0000 http://programmerbay.com/?p=3115

These are the following step to design a 2 bit Synchronous up counter using T Flip flop

Step 1: To design a synchronous up counter, first we need to know what number of flip flops are required. we can find out by considering a number of bits mentioned in the question. So, in this, we required to make 2 bit counter so the number of flip flops required is 2 [2n where n is a number of bits].

Step 2: After that, we need to construct a state table with an excitation table.

Note: To construct an excitation table from the state table you should know the excitation table of the respective flip flop, in this case, it is T flip flop. So check the excitation table forT flip flop Which is:

T Flip Flop Excitation Table

Present stateNext State    T
000
011
101
110

So, the above table is the excitation table for T Flip Flop.


State Table with  excitation  table

   Present State    Next State    Flip Flop
Q2Q1Q'2Q'1T2T1
000101
011011
101101
110011

Above the table is created as per follow :

When Q2 =0 which is the present state and Q2‘=0 which is the next state then T2 becomes 0 [As per excitation table, have a look ]
Similarly, if Q2 is 0 and Q2‘ is 1 then T2 becomes 1.
In a similar way, it goes on.

Step 3: After making the excitation table the next thing to do is dig out the equation from the boolean algebra or K map for the design of the counter. So For T1 and T2 we got 1 and Q1 .

K-Map

 

For T2  Flip flop,

k 2Bmap1
T2= Q1

For TFlip flop,

k 2Bmap2

 

T1=1

Step 4: Lastly according to the equation got from K map create the design for 2 bit synchronous up counter.

2 bit Synchronous up counter using T Flip flopIn the above design, T1 is getting high input and T2 is getting input from the output of the T1 flip flop.  A clock is attached to it which is in blue colour.
]]>
https://programmerbay.com/design-a-2-bit-synchronous-up-counter-using-t-flip-flop/feed/ 0
Design a 4 bit synchronous up counter using T flip flop https://programmerbay.com/design-a-4-bit-synchronous-up-counter-using-t-flip-flop/ https://programmerbay.com/design-a-4-bit-synchronous-up-counter-using-t-flip-flop/#respond Wed, 28 Feb 2024 15:34:00 +0000 http://programmerbay.com/?p=3113

These are the following steps to design a 4 bit synchronous up counter using T flip flop:

Step 1: To design a synchronous up counter, first we need to know what number of flip flops are required. we can find out by considering a number of bits mentioned in the question. So, in this, we required to make 4 bit counter so the number of flip flops required is 4 [2n where n is a number of bits].

Step 2: After that, we need to construct a state table with excitation table.
Note: To construct excitation table from state table you should know the excitation table of respective flip flop, in this case, it is T flip flop. So check the excitation table for T flip flop Which is:

T Flip Flop Excitation Table

Present stateNext State    T
000
011
101
110

So, the above table is the excitation table for T Flip Flop.


State Table with  excitation  table

   Present State    Next State    Flip Flop
Q4Q3Q2Q1Q'4Q'3Q'2Q'1T4T3T2T1
000000010001
000100100011
001000110001
001101000111
010001010001
010101100011
011001110001
011110001111
100010010001
100110100011
101010110001
101111000111
110011010001
110111100011
111011110001
111100001111

Above  table is created as per follow :

When Q4 =0 which is present state and Q4‘=0 which is next state then T4 become 0 [As per excitation table, have a look ]
Similarly, if Q4 is 0 and Q4‘ is 1 then T3  become 1.
In similar way it goes on .

Step 3: After making the excitation table the next thing  to do is dig out the equation from the boolean algebra or K map for the design of the counter. So, for T1 , T2, T3 and T4 we got 1,  Q1, Q1.Q2 and  Q1.Q2.Q3

K-Map


 For TFlip flop,

T4 4BIT
T4  Q1.Q2.Q3

 

For TFlip flop,

T3 2B4 2BBIT
T3= Q1.Q2

For T2  Flip flop,

T2 4BIT

 

T2= Q1

For TFlip flop,

T1 4BIT

 

T1=1

Step 4: Lastly according to the equation got from K map create the design for 4 bit synchronous up counter.

4 bit synchronous up counter using t

In above design T1 is getting input logic 1 and T2 is getting input from the output of the T1 flip flop and Tis getting input from the output of T1  and T2 lastly, Tis getting input from the output of TT2 and T3. A clock is attached to it which is in blue colour.

Related Posts:

Design a 3 bit synchronous up counter using T Flip flop?
Design a 2 bit Synchronous up counter using T Flip flop?

]]>
https://programmerbay.com/design-a-4-bit-synchronous-up-counter-using-t-flip-flop/feed/ 0
Design 3 bit synchronous up counter using T Flip flop? https://programmerbay.com/design-a-3-bit-synchronous-up-counter-using-t-flip-flop/ https://programmerbay.com/design-a-3-bit-synchronous-up-counter-using-t-flip-flop/#respond Sun, 25 Feb 2024 16:04:00 +0000 http://programmerbay.com/?p=3114

These are the following steps to Design a 3 bit synchronous up counter using T Flip flop:

Step 1: To design a synchronous up counter, first we need to know what number of flip flops are required. we can find out by considering a number of bits mentioned in the question. So, in this, we required to make 3 bit counter so the number of flip flops required is 3 [2n where n is a number of bits].

Step 2: After that, we need to construct state table with excitation table.
Note: To construct excitation table from state table you should know the excitation table of respective flip flop, in this case, it is T flip flop. So check the excitation table for T flip flop Which is:

T Flip Flop Excitation Table

Present stateNext State    T
000
011
101
110

So, the above table is the excitation table for T Flip Flop.

State Table with  excitation  table

   Present State    Next State    Flip Flop
Q3Q2Q1Q'3Q'2Q'1T3T2T1
000001001
001010011
010011001
011100111
100101001
101110011
110111001
111000111

Above  table is created as per follow :

When Q3 =0 which is present state and Q3‘=0 which is next state then T3 become 0 [As per excitation table, have a look ]
Similarly, if Q3 is 0 and Q3‘ is 1 then T3  become 1.
In similar way it goes on .

Step 3: After making the excitation table the next thing  to do is dig out the equation from the boolean algebra or K map for the design of the counter. So, for T1 , Tand T3 we got 1,  Q1 and Q1.Q2

K-Map

 

For TFlip flop,

 

3biit
T3= Q1.Q2

For T2  Flip flop,

3bit1
T2= Q1

For TFlip flop,

3biit2t

 

T1=1

Step 4: Lastly according to the equation got from K map create the design for 3 bit synchronous up counter.

design 2B3bit

In above design, T1 is getting input 1 and T2 is getting input from the output of the T1 flip flop and lastly, T3 is getting input from the output of T1  and T2 . A clock is attached to it which is in blue colour.

Popular Posts:

SQL: INSERT INTO statement 
SELECT DISTINCT statement 

]]>
https://programmerbay.com/design-a-3-bit-synchronous-up-counter-using-t-flip-flop/feed/ 0