Using int type to implement right shift of type unsingedint _ PHP Tutorial

Source: Internet
Author: User
The int type is used to implement the right shift operation of the unsingedint type. Many scripting languages do not contain unsingedint, such as PHP. Bitwise operations generally have no difference between int and unsingedint. except for the right shift operation, in int, replace 1 has many scripting languages without unsinged int, such as PHP. Bit operations generally have no difference between int and unsinged int, except for the right shift operation. in int, 1 is supplemented and 0 is supplemented in unsinged int. I 've been thinking for a long time, finally, I thought of a better method, but the number of shifts to the right of this method must be at least 1. In general, 0 shifted right is meaningless.

($ A> 1) & 0x7fffffff)> ($ n-1) Here $ n is the number of shifts to the right. $ N> = 1

For example, to implement md5 encryption, the following function is generally used, which can be implemented in PHP as follows:

Copy to ClipboardReference: [www.bkjia.com] function RotateLeft ($ a, $ n)
{
Return ($ a <$ n) | ($ a> 1) & 0x7fffffff)> (31-$ n); pay attention to the operator priority.
}

People who are interested in encryption and decryption should have encountered the same problems as me. I don't know if anyone has a better solution.

There are no unsinged int values for containers, such as PHP. Bit operations generally have no difference between int and unsinged int. apart from the right shift operation, the int is supplemented by 1...

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.