Thread: logical operation

  1. #1
    Registered User
    Join Date
    Feb 2020
    Posts
    23

    logical operation

    Hello

    logical operation between x and y give z

    Code:
    X Y Z
    0 0 0
    0 1 1
    1 0 1
    1 1 1
    there are three column R1, R2, R3
    if R1 is 1, R2 should be 1
    if R1 is 0 , R2 will be unchanged

    How to write c program for above logic operation ?


    OR Logic
    Code:
    0 | 0 = 0
    0 | 1 = 1
    1 | 0 = 1
    1 | 1 = 1
    AND Logic

    Code:
    0 & 0 = 0
    0 & 1 = 0
    1 & 0 = 0
    1 & 1 = 1
    Last edited by Parth12; 02-26-2020 at 12:16 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Parth12
    there are three column R1, R2, R3
    if R1 is 1, R2 should be 1
    if R1 is 0 , R2 will be unchanged
    So what's the point of R3? And what does this have to do with x, y and z?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2020
    Posts
    23
    Quote Originally Posted by laserlight View Post
    So what's the point of R3? And what does this have to do with x, y and z?
    sorry I have updated previous question because R1, R2, R3 create confuse so Now I am just using X, Y and Z

    assume X is status of flag, Y is status of bit and z show the change of Y when flag enable

    X flag can be enable and disable and Y is bit

    If X flag is disable, bit Y will not change but flag is set, bit Y should be high and Z show the change of y

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Parth12
    If X flag is disable, bit Y will not change but flag is set, bit Y should be high and Z show the change of y
    You had the good idea of drawing a truth table, so let's do that:
    Code:
    X Y Z
    0 0 0
    0 1 1
    1 0 1
    1 1 1
    This is the exact truth table you drew in post #1, and indeed it corresponds to what you described. You also drew the truth table for OR, and it corresponds to this exactly. So you have answered your own question: implement an OR.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2020
    Posts
    23
    I am confuse with following logic operation, specially with shift operation
    What will the final result of X

    Code:
    X = 0 | 0 << 0X = 0 | 0
    X = 0
    
    
    X = 0 | 1 << 1
    X = 0 |
    X = 
    
    
    X = 1 | 0 << 1
    X = 1 |
    X = 
    
    
    X = 1 | 1 << 1
    X = 0 
    X =

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. logical not !7 logical whaaaa?
    By Charbot in forum C Programming
    Replies: 2
    Last Post: 03-22-2011, 07:19 PM
  2. logical operation
    By siperi in forum C Programming
    Replies: 13
    Last Post: 11-08-2010, 10:28 AM
  3. arithmatic vs logical shift operation
    By onebrother in forum C Programming
    Replies: 2
    Last Post: 02-21-2008, 04:21 AM
  4. logical operation functions in c; And, Or, Xor, Not etc..
    By Jasonx521 in forum C Programming
    Replies: 6
    Last Post: 10-03-2006, 12:24 AM
  5. Logical Operation Sequence ?!?
    By Halo in forum C Programming
    Replies: 2
    Last Post: 04-16-2002, 12:49 PM

Tags for this Thread