C ++ bit alignment operation

Source: Internet
Author: User

See a macro: # define pad_align (x, mask) (x + mask )&~ Mask)

 

First, you must understand the alignment operation, that is, when the number of digits is not multiple of Y, the last y is used to complete. For example, 12 is not a multiple of 8. If it is aligned with 8, the number of digits should be 16. For example, when a 24-Bit Bitmap is stored, the number of rows must be a multiple of 32.

Let's look at this macro again. If one of the following mask (number of 00011111,1) bits of x exists (not all values 0 cannot be rounded out by mask + 1, here the mask is 2 ^ N-1 ), the addition of a mask is the completion, and the number of digits is increased, but it is still not divisible by the mask + 1. Don't worry ~ Mask is followed by 0, so it can be divisible by mask + 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.