answersLogoWhite

0


Best Answer

AND, OR, and NOT are the most common ones. There are others, too, such as XOR.




AND, OR, and NOT are the most common ones. There are others, too, such as XOR.




AND, OR, and NOT are the most common ones. There are others, too, such as XOR.




AND, OR, and NOT are the most common ones. There are others, too, such as XOR.


User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

The four logical operators are AND, OR, XOR and NOT. These operators are used to evaluate operands composed of boolean expressions.

A boolean expression is any expression that returns a boolean value. A boolean value is a data type of arbitrary length (dependant upon the implementation of the programming language) but is typically 8 bits in length. When all bits are off, the value is false but when all bits are on, the value is true. Thus 0x00 is false while 0xff is true.

When evaluating a boolean expression, the operands of that expression need not themselves be boolean. For instance, given the following definition of a string:

string s = "Hello world"

The boolean expression s=="" returns 0x00 because s is not equal to an empty string but the expression s=="Hello world" returns 0xff because s is equal to "Hello world".

NOT is a unary operator which has only one operand. If the operand evaluates false, then the return value is true. If the operand evaluates true, the return value is false. In other words we use the NOT operator to invert all the bits in the boolean value.

Thus we can say that NOT (s=="") returns 0xff because s=="" evaluates false (s is not an empty string) and NOT (false) evaluates true.

The other operators are binary operators with two operands. The "truth tables" for each of these operators are as follows:

true AND true == true

true AND false == false

false AND true == false

false AND false == false

true OR true == true

true OR false == true

false OR true == true

false OR false == false

true XOR true == false

true XOR false == true

false XOR true == true

false XOR false == false

Note that AND returns true only when both operands evaluate true while OR returns true when one or both operands are true. XOR is the eXclusive-OR operator which only returns true when one (and only one) operand is true.

You will note that there are 4 possible outcomes for each of these binary operators and that each of the tables produces a unique combination of true and false results depending on the two inputs (which are in the same order for each table). If we translate these results into binary values we can see that AND produces 1000 (true, false, false, false), OR produces 1110 (true, true, true, false) and XOR produces 0110 (false, true, true, false). With 4-bits there are clearly 16 possible combinations of 1 and 0 bits, but the logical operators only produce 3 of them. However, we can combine these three operators in various ways along with NOT to produce seven more tables:

NOT (true AND true) = false

NOT (true AND false) = true

NOT (false AND true) = true

NOT (false AND false) = true

NOT (true OR true) = false

NOT (true OR false) = false

NOT (false OR true) = false

NOT (false OR false) = true

NOT (true XOR true) = true

NOT (true XOR false) = false

NOT (false XOR true) = false

NOT (false XOR false) = true

(NOT true) AND true = false

(NOT true) AND false = false

(NOT false) AND true = true

(NOT false) AND false = false

(NOT true) OR true = true

(NOT true) OR false = false

(NOT false) OR true = true

(NOT false) OR false = true

true AND (NOT true) = false

true AND (NOT false) = true

false AND (NOT true) = false

false AND (NOT false) = false

true OR (NOT true) = true

true OR (NOT false) = true

false OR (NOT true) = false

false OR (NOT false) = true

The remaining 6 tables are only of interest to academics and are not particularly useful to programmers. Those 6 are the truth tables that produce false regardless of input, or simply return the first operand, or the second operand, or the logical NOT of any of these three.

It should be noted that some languages do not provide a logical operator for XOR. This is because XOR can be simulated using AND, OR and NOT. That is, given two inputs, a and b, a XOR b can be determined from (a AND (NOT b)) OR ((NOT a) AND b).

It should also be noted that logical operators are not the same as bitwise logic operators. Bitwise logic operators work similarly to the logic operators in terms of the truth tables, but they compare on a bit-by-bit basis. Thus 0101 AND 0110 outputs 0100 because bit 2 is the only bit that is set in both inputs and is therefore the only bit that evaluates true according to the AND truth table. The NOT operator also works differently in that it flips all the bits in the operand, effectively returning the ones complement of its input (it is often referred to as the inverse operator for that reason).

The logical bitwise operators are typically used to read and write the individual bits in a bit field (or bitmap). Such values are typically used to denote which features within a set of features are enabled or disabled. While this can save memory by cramming more booleans into a single word, the downside is that the data is slower to read and write because of the additional operations required to access the individual bits. However, some architectures are optimised to take advantage of this.


This answer is:
User Avatar

User Avatar

Wiki User

7y ago

Logical operators are typically used to control the flow of execution:

if (x && y) {

// jump here when x and y are both true

} else if (x y) {

// jump here when either x or y is true

} else {

// jump here when both x and y are false

}

while (!z) {

// iterate over this code block while z is false

}

The three logical operators are NOT, AND and OR. In C Programming, these operators are represented by the tokens !, && and , respectively.

The operands to these operators must be Boolean expressions; expressions that evaluate true or false. The output of a logical operator is also a Boolean expression. Thus the output of one logical operator can be used as input for another, thus allowing us to create highly complex Boolean expressions. However, it is best to keep Boolean expressions as simple as possible in the interests of readability.

We use truth tables to examine the output of the logical operators given all the possible input operands, denoting true and false with the symbols T and F respectively. The NOT operator is a unary operator so it only has one operand:

!F = T

!T = F

In other words, the NOT operator outputs the logically reversed state of its input. This stands to reason because when something is not true then it must be false, and vice versa.

The AND and OR operators are binary operators and therefore require two operands. Given two operands with two possible states there are four possible evaluations for each operator:

F && F = F

F && T = F

T && F = F

T && T = T

F F = F

F T = T

T F = T

T T = T

Note that in two of the four cases in each operator, there is no need to completely evaluate both operands. With logical AND, when the left-hand operand evaluates false, then entire expression must be false. Similarly, with logical OR, when the left-hand operand evaluates true, the entire expression must be true. One way we can exploit this "partial evaluation" is when working with pointers:

void f (int* p) {

if (p!=NULL && *p==42) {

// p is non-NULL and it points to the value 42

}

}

Obviously we cannot dereference a NULL pointer, however the expression *p==42 is only evaluated when p!=NULL evaluates true. If it evaluates false, then the entire expression must be false, so there's point in attempting to evaluate *p==42.

The AND and OR truth tables are just two of 16 possible truth tables. We know there are 16 because given two inputs there are four possible outputs and therefore 4^2 = 16 unique permutations for those outputs. We can simulate these permutations through simple combinations of AND, OR and NOT. The following table illustrates the 4 outputs for each truth table (labelled 0 to F) given two inputs a and b such that ab is FF, FT, TF and TT for each output, respectively. The examples show how the output can be obtained.

0 = FFFF e.g., !(a !a)

1 = FFFT e.g., a && b

2 = FFTF e.g., a && !b

3 = FFTT e.g., a

4 = FTFF e.g., !a && b 5 = FTFT e.g., b

6 = FTTF e.g., (!a && b) (a && !b)

7 = FTTT e.g., a b

8 = TFFF e.g., !(a b)

9 = TFFT e.g., (!a && !b) (a && b)

A = TFTF e.g., !b

B = TFTT e.g., a !b

C = TTFF e.g., !a D = TTFT e.g., !a b

E = TTTF e.g., !(a && b)

F = TTTT e.g., a !a

The first and last permutations (0 and F) aren't very useful. The first evaluates false regardless of its inputs while the last evaluates true regardless of its inputs. We can't use these in a Boolean expression, but the exist nevertheless.

It is worth keeping in mind that logical operations can often be expressed in different ways. For instance, truth table B could be implemented as !(a && !b) and truth table D as !(!a && b), which would better illustrate the inverse nature of the last eight truth tables (8 to F). But when given the choice, always choose the expression that best illustrates the logic. If the logic is so complex that it inhibits readability, break the logic down into simpler expressions.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

the 'and' and 'or' operators written in java as '&&' and '' respectively.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

arithmetic operator are the operator which used to perform some basic operations like addition, subtraction ,multiplication (*),division(/).

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

AND, OR, and NOT are the most common ones. There are others, too, such as XOR.


This answer is:
User Avatar

User Avatar

Wiki User

12y ago

AND an OR

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the arithmetic and logical operator?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is difference between conditional operator and bitwise operator?

A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.


How many types of operators?

The different types of operators are: Assignment operator- This is used to assign values to variables. Ex: = Arithmetic Operators - These are used to perform arithmetic operations. Ex: +, -, *, /, % Logical Operators - These are used to perform logical checks like: I < 10 or x == Y etc.


What are the different types of Operators available in java?

arithmatic operator +,-,*,/,% assigment oprator == logical operator &,|,^,&&,,! bitwise opertor &,|,^ left shift << right shift >> left shift zero fill << assignment operator +=,-=,*=,/=


Explain the Difference between bitwise operator ' and ' and address operator ' and ' of pointer?

The bitwise logical operator and (&) calculates the bitwise logical and of two integral values. It is a binary operator.The address of (&) operator returns the address of the value to its right. It is a unary operator.The distinction between the two is one of context. The logical and operator will follow (and be preceeded by) a value, while the address of operator will follow an operator.


Logical or operator can be compared to what in terms of precedence?

The logical OR operator can be compared to ____ in terms of precedence.

Related questions

What is operator in java?

An operator is a symbol that does something in Java. for ex: "+" is an arithmetic operator that adds two numbers. ">" is a logical operator that checks if one number is greater than the other. There are many different types of operators in Java like Arithmetic, Logical, Relational and Assignment operators


What are different type's operators?

The different types of operators are as follows: *Arithmatic operator *Relational operator *Logical operator *Assignment operator *Increment/Decrement operator *Conditional operator *Bitwise operator *Special operator


What is difference between conditional operator and bitwise operator?

A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.


How many types of operators?

The different types of operators are: Assignment operator- This is used to assign values to variables. Ex: = Arithmetic Operators - These are used to perform arithmetic operations. Ex: +, -, *, /, % Logical Operators - These are used to perform logical checks like: I < 10 or x == Y etc.


What is an arithmetic operator in c?

+


Full form of ALU?

ARITHMETIC AND LOGICAL UNIT Anand bhat(mca@kiit-870024)


ALU stand for?

Arithmetic logic unit


The unit that performs the arithmetic and logical operations within the processor?

The unit that performs the arithmetic and logical operations within the processor is called the Arithmetic Logic Unit (ALU).


Arithmetic operator that divides contents of a cell?

The arithmetic operator that divides contents of a cell is the front slash. =A3/B3


What is an arithmetic operator that multiplies?

Multiplication


What logical operator is used to reverse the boolean operator?

NOT


What is difference between the arithmetic operation and logical operation?

An arithmetic operation combines two numbers while a logical operation uses two logical values which can be true or false. The arithmetic operation uses adding or subtraction to reach the correct answer.