Finite State Machine (4 Bit Numbers) > Java Program

Theoretical Computer Science

Finite State Machine (4 Bit Numbers) > Java Program


import java.io.*; 
class FSM 


public static void main (String args[])throws IOException 

int fsm1,i,base=2,no=4,ans=0,ans1=0,m=0,m1=0,z=0; 
int b[]={0,0,1,1,2,2,3,3}; 
int c[]={0,1,0,1,0,1,0,1}; 
DataInputStream in=new DataInputStream(System.in); 
System.out.println("Enter no of bits in Binary no"); 
fsm1=Integer.parseInt(in.readLine()); 
int a[]=new int[fsm1]; 
System.out.println("Enter Binary number"); 
for(i=0;i<fsm1;i++) 

a[i]=Integer.parseInt(in.readLine()); 

//TRANSITION    TABLE  FOR  FSM 
System.out.println("Transition Table for fsm"); 
System.out.println("\t"+0+"\t"+1); 
System.out.print("-------------------------"); 
for(i=0;i<8;i++) 

if (i==0||i==2||i==4||i==6) 

System.out.println(); 
System.out.print("Q"+z+"  |"); 
z++; 

ans1=(b[i]*base+c[i])%no; 
System.out.print(" Q"+ans1); 

System.out.println(); 
System.out.println(); 
//TRANSITION    DIAGRAM 
System.out.println("Transition diagram of fsm"); 
System.out.print("-->Q"+ans); 
for(i=0;i<fsm1;i++) 

ans=(m*base+a[i])%no; m=ans; System.out.print("-->Q"+ans); 

System.out.println(); 


/*OUTPUT of  finite-state machine (fsm): 
Enter no of bits in Binary no 

Enter Binary number 
1 1 1 0 
Transition Table for fsm
       0            1 
------------------------- 
Q0  |   Q0      Q1 
Q1  |   Q2      Q3 
Q2  |   Q0      Q1 
Q3  |   Q2      Q3 
Transition Diagram of fsm  
-->Q0-->Q1-->Q3-->Q3-->Q2    */

Comments

Popular posts from this blog

Intermediate Code Generation > C Program