Logical Right Shift function SRL () and arithmetic right shift function SRA ()

Source: Internet
Author: User

For example, a signed bit of the 8-bit binary number 11001101, the logical right shift regardless of the sign bit, if the move one becomes 01100110. The arithmetic right moves to the tube sign bit, the right one becomes 10100110.

Logical left shift = arithmetic left shift, right unified add 0

Logical right SHIFT, left unified add 0

Arithmetic is shifted right, and the number added to the left is related to the symbol

Attached code:

intSraintXintk) {    intXSRL = (unsigned) x >>K; intW =sizeof(int) <<3; returnXsrl |= (-1<< (wk));} Unsigned srl (unsigned x,intk) {unsigned Xsra= (int) x >>K; intW =sizeof(int) <<3; returnXsra &= ~ (-1<< (W-k));}

e.g:1010101010, where [] bit is the number added

Shift logic left one: 010101010[0]

Arithmetic left shift one: 010101010[0]

Logical right SHIFT one: [0]101010101

Arithmetic right shift one: [1]101010101

Logical Right Shift function SRL () and arithmetic right shift function SRA () (GO)

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.