This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

4 out of 5 Logic

Hi All,

I am implementing 2/3 logic as follows:
Three inputs a,b,c.
d will hold 2/3 value.

d=(a&b)|(b&c)|(c&d);

whether there is any combitation for 4/5 simillar to this?

a,b,c,d,e are 5 inputs then 4 out of 5 logic will be based on the following 10 combinations.

ab,ac,ad,ae
bc,bd,be,
cd,ce,
de

whether there is any simple way to find 4/5 logic...using |,& and !

  • I think it would probably help if you handle it as a bitmap:

    If you want 4 out of 5 to be "True", then that means that only 1 can be "False" - doesn't it...?

  • Besides Andys apt note for a situation where you require n-1 true symbols, you can also consider the more general solution for m out of n:

    if ((a!=0) + (b!=0) + (c!=0) + ... > limit) {
    }
    

  • Neat source code?

    Portable source code?

    Small executable code?

    Fast executable code?

    Or what?

    (note that some of the above may be mutually exclusive)

  • Hi,
    Thanks for your response....

    I implemented the following code to fing 4 out of 5 frames are correct and each frame is 12 bytes length.....

    tDBYTE processFrames()
    {
      tDBYTE lcounter = 5,i,j,k,lcounter1=0;
      tDBYTE Tempdata=0,compData=0,FrameError=0;
       for(i=0;i<5;i++)
            {
                     for(j=i+1;j<5;j++)
                     {
                               for(k=1;k<12;k++)
                               {
                                     ////////////////////////////////////////////
                                     if((i==0||i==2||i==4))
                                             {
                                                    Tempdata=sortedData[i][k];
                                             }
                                             else
                                             {
                                               Tempdata=~sortedData[i][k];
                                             }
    
                                             if(j==0||j==2||j==4)
                                             {
                                                     compData=sortedData[j][k];
                                             }
                                             else
                                             {
                                                     compData=~sortedData[j][k];
                                             }
    
                                             ////////////////////////////////////////////
                                     if(Tempdata!=compData)
                                             {
                                               FrameError=TRUE;
                                               break;
                                             }
                                        ///////////////////////////////////////////
                               }
                            if(FrameError==TRUE)
                             {
                                    FrameError=FALSE;
                                    failedFrame[lcounter1++]=TRUE;
                             }
                             else
                             {
                                    failedFrame[lcounter1++]=FALSE;
                             }
                     }
            }
            if((failedFrame[0] == TRUE) && (failedFrame[1] == TRUE) && (failedFrame[2] == TRUE) && (failedFrame[3] == TRUE))
            {
                    lcounter--;
                bFramefail[0] = TRUE; // 1st Frame Failed
            }
            if((failedFrame[0] == TRUE) && (failedFrame[4] == TRUE) && (failedFrame[5] == TRUE) && (failedFrame[6] == TRUE))
            {
               bFramefail[1] = TRUE; // 2nd Frame Failed
               lcounter--;
            }
            if((failedFrame[1] == TRUE) && (failedFrame[4] == TRUE) && (failedFrame[7] == TRUE) && (failedFrame[8] == TRUE))
            {
               bFramefail[2] = TRUE; // 3rd Frame Failed
               lcounter--;
            }
            if((failedFrame[2] == TRUE) && (failedFrame[5] == TRUE) && (failedFrame[7] == TRUE) && (failedFrame[9] == TRUE))
            {
               bFramefail[3] = TRUE; //4th Frame failed
               lcounter--;
            }
            if((failedFrame[3] == TRUE) && (failedFrame[6] == TRUE) && (failedFrame[8] == TRUE) && (failedFrame[9] == TRUE))
            {
               bFramefail[4] = TRUE; //5th Frame failed
               lcounter--;
            }
             return lcounter;
    }
    

    here the Odd frames are inverse of the even frames....
    so only ((i==0||i==2||i==4)) this conditions are used...
    This code takes more time to execute.....
    i use the failed frame array to compare the 5 frames for ab,ac,ad,ae.....logic...and return the result

  • Are you really happy with the size of that code?

    What will happen if your constant 5 is updated to 70?
    What will happen if the packet size is updated from 12 to 32768 bytes?

    Should the code size grow in this way with the size of the constants?

    Dod you consider reading the previous posts?

    Did you understand the previous posts?

    Have you considered what "four-out-of-five" means?
    What would be the difference relative to "one-out-of-five"?
    In relation to "not-one-out-of-five"?
    How do you implement AND logic with just OR and NOT?
    How do you implement OR logic with just AND and NOT?
    What other advantages can be taken if not limited to the logic levels 0 and 1?

  • I guess the schools quit teaching DeMorgan's Theorem. What a shame. I learned it when I was 13. It solves a lot of problems.

    Jon