The left-shift operation, the right shift operation, the bitwise negation operation of the built-in mathematical function of awk in Linux

Source: Internet
Author: User
Tags arithmetic bitwise
In programming, one of the bitwise operator operators. In C + +, the shift operators have binocular shift operators:<< (left) and >> (move right). An expression consisting of a shift operator also belongs to an arithmetic expression whose value is an arithmetic value. The left shift operation is to shift the operand of a bits to the left by the specified number of digits, remove the bit, and all the vacancies on the right complement 0. The right shift operation is to move a bits operand to the right by the specified number of digits to move, remove the bit to be discarded, leave the left blank or all fill 0, or complement the symbol bit, depending on the machine. In a machine that uses the complement as a machine, a positive sign is 0, and a negative number has a sign bit of 1.
In shift operations, the results of the byte, short, and char types shift to the int type, and when the byte, short, char, and int are shifted, the actual number of moves is the amount of movement and the remainder of the 32, which is the same result as the shift 33 times and the displacement 1 times. When you move a long value, you specify that the number of moves is the number of moves and the remainder of the 64, which is the same result of moving 66 times and moving 2 times.

Instance:
[Root@legion10 ~]# echo 233 | awk ' {print lshift ($1,5), Rshift ($1,5), $} ' 7456 7 233 [Root@legion10 ~]#

Analytical:
[Root@legion10 ~]# echo 233 | awk ' {print lshift ($1,5), Rshift ($1,5), $} ' 7456 7 233 [Root@legion10 ~]# cat 2 Dec             bin             |       Dec                     bin 233             0000011101001   |       233                     11101001 7456            1110100100000   |       7                       00000111----Left-shift 5-bit-------------        |   ----Right 5-bit------------  [Root@legion10 ~]#

A right shift operation computes IP.
[Root@legion10 ~]# Echo 134744072|awk ' { 	a=0xff000000; 	b=0xff0000; 	c=0xff00; 	D=0xff; 	E=rshift (and ($1,a),); 	F=rshift (and ($1,b); 	G=rshift (and ($1,c), 8); 	H=and ($1,d); 	printf ("%d.%d.%d.%d\n", E,f,g,h)} '  8.8.8.8 [Root@legion10 ~]#

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.