jeudi 2 août 2018

How to convert nested if-else statement into an auto-generated format?

I am trying to decode a set of binary encoding. lets say: 0101010101010101.

Every two binary bit determine the meaning of the next two bits. which I mean there is some dependency to decode.

The most trivial way is implement a series of nested if-else statement:

ex. if first-two bit == 00
        if second-two bit == 00
        else if second-two bit == 10
           ......
    else if first-two bit == 01
        if second-two bit == 00
        else if second-two bit == 10
           ......

    else if first-two bit == 10
         ........

    else if first-two bit == 22
         ........

As you can seen, if there are total 16 bits to decode. I would have a write a very nested if- else statement to explain all the combinations.

So I am think to auto generate all the tedious code for easily use. I am wondering if anyone have some experience to convert the nested if -else statement into some simpler format for easier auto generation.

BTW. I have thought the write the code in FSM, but I found I have to build so many states. which is also not good for manually written.

Aucun commentaire:

Enregistrer un commentaire