On the understanding and experiment of logical operation XOR in Shell programming

Source: Internet
Author: User

Logical operations in shell programming, with or without, short-circuit operations, XOR operations, we use the simplest way to understand the XOR.

XOR: ^
XOR two values, same as false, different for true

Understandably, two values refer to binary values, two 1 or two 0 results are false [0], and two different values result in [1].

For example:

Binary
decimal
10 01010
22 10110
XOR result 28 11100

How does that differ or how does it reflect value in shell programming? The following experiment can be used in temporary variables.

#利用临时变量将a b进行互换值[[email protected] ~]#a=6[[email protected] ~]#b=8[[email protected] ~]#tmp=$a[[email protected] ~]#a=$b[[email protected] ~]#b=$tmp[[email protected] ~]#echo $a $b8 6[[email protected] ~]#b=8[[email protected] ~]#a=6[[email protected] ~]#a=$[a^b]#此时的a^b按照二进制运算,则结果为如下计算结果0110 61000 81110 14[[email protected] ~]#echo $a $b14 8[[email protected] ~]#b=$[a^b]#此时的a^b按照二进制运算,则结果为如下计算结果1110 141000 80110 6[[email protected] ~]#echo $a $b14 6[[email protected] ~]#a=$[a^b]#此时的a^b按照二进制运算,则结果为如下计算结果1110 140110 61000 8[[email protected] ~]#echo $a $b8 6

On the understanding and experiment of logical operation XOR in Shell programming

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.