Mealy Machine for 1’s Complement

After converting a number to its binary form, replace every one of the number with 0 and every 0 with 1, then the resulting number will be known as 1, s compliment of that binary number.

Input-1 :
Output-1 : 

Input-2 :
Output-2 :

Approach :

  1. First make a initial state.
  2. Then convert each 0 to 1 and each 1 to 0, and reach to next possible state.
  3. after performing step 2 on each digit of binary number, reach at some final state to complete the process.

Design Mealy Machine :

Take a initial state say q1, and if the input is found 0, convert it to 1, remain at same state and check for another input alphabet.

If state q1 takes input alphabet is 1, then convert it to 0 and remain at same state.

Step-3:As after converting all alphabet, it is on same state then this state will be final state as well.

Example :
Suppose a string 10001 and start parsing from left to right. Every 0 will be replaced by 1 and every one is replaces by 0. Then the output is 01110.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.