Key Difference – Bitwisevs Logical Operators
In programming, there are situations to perform mathematical computations. An operator is a symbol of programming languages to perform specific logical or mathematical functions on a value or a variable. There are various operators in programming languages. Some of them are arithmetic operators, relational operators, logical operators, bitwise operators and assignment operators. Arithmetic operators support mathematical operations such as addition (+), subtraction (-), division (/), multiplication (*), modulus (%), incrementing (++) and decrement (–). Relation operators are >, > =, <, <=, == or !=. These operators help to find the relationship of operands. Assignment operators assign values from right side operand to left side operand. Bitwise operators are &, |, ^. Logical operators are &&, ||,!. This article discusses the difference between bitwise and logical operators. Thekey differencebetween Bitwise and Logical operators is thatBitwise operators work on bits and perform bit by bit operations while logical operators are used to make a decision based on multiple conditions.
内容
1.Overview and Key Difference
2.什么是位运算符
3.What are Logical Operators
4.Similarities Between Bitwise and Logical Operators
5。Side by Side Comparison – Bitwise vs Logical Operators in Tabular Form
6。概括
什么是位运算符?
钻头操作员处理位,并通过位操作执行。在诸如加法,减法,乘法,除法等计算中。值将其转换为二进制. Those operations are performed on bit level. Bit-level processing is used to increase speed and to save power. Some examples of Bitwise operators are as follows. The & represents bitwise AND. The | represents bitwise OR. The ^ represents bitwise exclusive OR. The ~ is the complement. The << symbol is to represent the left shift while >> symbol represents the right shift.
钻头和操作如下。当x和y是操作数时,x具有值0,y具有值0,然后是0。然后位于0,为0。当x和y都有1个,位和1。仅当两个操作数包含值1时,输出才是1。假设20和25为两个值。20的二进制为10100。25的二进制为11001。11001。这两个数字为10000。当逐个点和操作执行时,仅在两个操作数包含一个时,一个值才能。
钻头或操作如下。当x和y是操作数时,x具有值0,y具有值0,然后是0。当x为0且y为1时,输出为1时。IS 1.当x和y都具有值1时,输出为1。从两个操作数中,如果一个操作数为1,则是1个操作数,则为1。假设20和25为两个值。20的二进制为10100。25的二进制为11001。比特或20和25的二进制为11101。
如果两个值都不同,钻头XOR操作员将获得1个。当x和y操作数为零时,xor xor为0。当x为0和y时,输出为1时。1,然后输出为0。20和25的位XOR为01101。〜符号是取值。二进制值为20为10100。补体为〜20 =01011。将其转换为零并将零转换为零。
The << is the binary left shift operator. The left operands value is moved left by the number of bits specified by the right operand. In example 5 << 1, the binary value of 5 is 0101. 0101<<1 is 1010. The >> is the binary right shift operator. The left operands value is moved right by the number of bits specified by the right operand. As an example, 5 >>1, 0101 >> 1 is 0010.
What are Logical Operators?
The logical operators are used to make a decision based on multiple conditions. The && symbol represents the logical AND. The || symbol represents the logical OR. The ! symbol represents the logical NOT. In logical AND, if both operands are non zero, then the condition becomes true. In logical OR, if both operands are non zero, then the condition becomes true. The ! operator can reverse the logical status of the operand. If a condition is true, then Logical NOT operator will make it false. The true represents value 1, and falsely represents value 0.
When variable x is holding the value 1 and variable y is holding the value 0, the logical AND that is (x && y) is false or 0. The logical OR that is (x || y) will give true or 1. The NOT operator reverses the logical status. When x is having value 1, then ! x is 0. When y is having value 0, then !y is 1.
What is the Similarity Between Bitwise and Logical Operators?
- 两者都是编程中的运算符,以在值或变量上执行特定的逻辑或数学函数。
位和逻辑运算符有什么区别?
比特与逻辑运算符 |
|
Bitwise Operator是编程语言提供的运算符类型来执行计算。 | 逻辑操作员是编程语言提供的一种运算符,用于执行基于逻辑的操作。 |
功能 | |
Bitwise operators work on bits and perform bit by bit operations. | 逻辑运营商用于根据多种条件做出决定。 |
主题 | |
Bitwise operators are &, |, ^, ~, <<, >>. | 逻辑运算符是&&,||,! |
概括– Bitwisevs Logical Operators
在程序设计中,有必要做这个tical and logical operations. They can be achieved using operators. There are various types of operators. This article discussed the difference between two operators such as bitwise operators and logical operators. The difference between Bitwise and Logical operators is that Bitwise operators work on bits and perform bit by bit operations while logical operators are used to make a decision based on multiple conditions.
下载位于位的PDF与逻辑运算符
You can download the PDF version of this article and use it for offline purposes as per citation note. Please download the PDF version here:Difference Between Bitwise and Logical Operators
Reference:
1. tutorialspoint.com。“ C运营商。”The Point.Available here
发表评论