0% found this document useful (0 votes)
70 views

A Whirlwind Tour of Python 2

This document describes how to construct a Mealy machine that takes a binary number as input and replaces the first 1 in each substring starting with 1 with a 0. It involves creating a two state Mealy machine with states labeled 0 and 1, and transitions that output 0 when reading the first 1 in a substring, and output the input otherwise. Running test strings demonstrates it works as intended by performing this "bit stuffing" operation.

Uploaded by

Akash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

A Whirlwind Tour of Python 2

This document describes how to construct a Mealy machine that takes a binary number as input and replaces the first 1 in each substring starting with 1 with a 0. It involves creating a two state Mealy machine with states labeled 0 and 1, and transitions that output 0 when reading the first 1 in a substring, and output the input otherwise. Running test strings demonstrates it works as intended by performing this "bit stuffing" operation.

Uploaded by

Akash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Mealy

 Machine  –  Exercise  

Problem:  

Construct  a  Mealy  machine  which  takes  a  binary  number  and  replaces  the  first  1  with  a  0  from  
every  substring  starting  with  1.    For  example,  0001001110  becomes  0000000110.    This  type  of  
“bit  stuffing”  may  be  used  in  data  transmission  and  telecommunications  for  run-­‐length  coding  to  
limit  the  number  of  consecutive  bits  of  the  same  value.    A  bit  of  the  opposite  value  is  inserted  
after  the  maximum  allowed  number  of  consecutive  bits.  

Solution:  

Open  JFLAP  and  create  a  Mealy  machine  with  an  initial  state.    Set  its  label  to  a  “0”  to  remember  that  a  
zero  is  read.    Next,  add  a  second  state  to  remember  that  a  “1”  was  read.    Label  this  with  a  “1”.  

 
Four  transitions  will  be  needed.  
1. At  q0,  a  0  is  read  so  a  loopback  to  q0  is  needed.  Output  a  0.  
2. At  q0,  a  1  is  read  so  a  transition  to  q1  is  needed.    Output  a  0  since  this  is  the  first  1  in  a  substring  
starting  with  a  1.  
3. At  q1,  a  0  is  read  so  a  transition  to  q0  is  needed.    Output  a  0.  
4. At  q1,  a  1  read  so  a  loopback  to  q1  is  needed.    Output  a  1.  

 
Run  some  test  strings  using  Input  >  Multiple  Runs.  

 
Recall  that  a  Moore  machine  is  state  machine  whose  output  is  determined  solely  by  its  current  state  
while  a  Mealy  machine  is  a  state  machine  whose  output  is  determined  both  by  its  current  state  and  its  
input.    In  this  example,  we  implement  a  Mealy  machine  that  uses  fewer  states  than  a  Moore  machine  
for  this  same  problem  because  we  are  able  to  check  both  the  input  and  the  current  state  at  the  same  
time.    A  machine  which  needs  to  “remember”  both  would  require  more  states.  

You might also like