Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Presumably, a <code>char</code> has eight bits, so <code>unsigned char b = x</code> takes the low eight bits of x.</p> <p>The mask with 0x22110 extracts bits 4, 8, 13, and 17 (numbering from 0 for the least significant bit). So, in the multiplication by 0x0802, we only care about what it places at those bits. In 0x802, bits 1 and 11 are on, so this multiplication places a copy of the eight bits of <code>b</code> in bits 1 through 8 and another copy in bits 11 through 18. There is no overlap, so there are no effects from adding bits that overlap in more general multiplications.</p> <p>From this product, we take these bits:</p> <ul> <li>Bit 4, which is bit 3 of <code>b</code>. (Bit 4 from the copy starting at bit 1, so bit 4–1 = 3 of <code>b</code>.)</li> <li>Bit 8, which is bit 7 of <code>b</code>. (8–1 = 7.)</li> <li>Bit 13, which is bit 2 of <code>b</code>. (13–11 = 2.)</li> <li>Bit 17, which is bit 6 of <code>b</code>. (17–11 = 6.)</li> </ul> <p>Similarly, the mask by 0x88440 extracts bits 6, 10, 15, and 19. The multiplication by 0x8020 places a copy of <code>b</code> in bits 5 to 12 and another copy in bits 15 to 22. From this product, we take these bits:</p> <ul> <li>Bit 6, which is bit 1 of <code>b</code>.</li> <li>Bit 10, which is bit 5 of <code>b</code>.</li> <li>Bit 15, which is bit 0 of <code>b</code>.</li> <li>Bit 19, which is bit 4 of <code>b</code>.</li> </ul> <p>Then we OR those together, producing:</p> <ul> <li>Bit 4, which is bit 3 of <code>b</code>.</li> <li>Bit 6, which is bit 1 of <code>b</code>.</li> <li>Bit 8, which is bit 7 of <code>b</code>.</li> <li>Bit 10, which is bit 5 of <code>b</code>.</li> <li>Bit 13, which is bit 2 of <code>b</code>.</li> <li>Bit 15, which is bit 0 of <code>b</code>.</li> <li>Bit 17, which is bit 6 of <code>b</code>.</li> <li>Bit 19, which is bit 4 of <code>b</code>.</li> </ul> <p>Call this result <code>t</code>.</p> <p>We are going to multiply that by 0x10101, shift right by 16, and assign to <code>b</code>. The assignment converts to <code>unsigned char</code>, so only the low eight bits are kept. The low eight bits after the shift are bits 24 to 31 before the shift. So we only care about bits 24 to 31 in the product.</p> <p>The multiplier 0x10101 has bits 0, 8, and 16 set. Thus, bit 24 in the result is the sum of bits 24, 16, and 8 in <code>t</code>, plus any carry from elsewhere. However, there is no carry: Observe that none of the set bits in <code>t</code> are eight apart, as the bits in the multiplier are. Therefore, none of them can directly contribute to the same bit in the product. Each bit in the product is the result of at most one bit in <code>t</code>. We just need to figure out which bit that is.</p> <p>Bit 24 must come from bit 8, 16, or 24 in <code>t</code>. Only bit 8 can be set, and it is bit 7 from <code>b</code>. Deducing all the bits this way:</p> <ul> <li>Bit 24 is bit 8 in <code>t</code>, which is bit 7 in <code>b</code>.</li> <li>Bit 25 is bit 17 in <code>t</code>, which is bit 6 in <code>b</code>.</li> <li>Bit 26 is bit 10 in <code>t</code>, which is bit 5 in <code>b</code>.</li> <li>Bit 27 is bit 19 in <code>t</code>, which is bit 4 in <code>b</code>.</li> <li>Bit 28 is bit 4 in <code>t</code>, which is bit 3 in <code>b</code>.</li> <li>Bit 29 is bit 13 in <code>t</code>, which is bit 2 in <code>b</code>.</li> <li>Bit 30 is bit 6 in <code>t</code>, which is bit 1 in <code>b</code>.</li> <li>Bit 31 is bit 15 in <code>t</code>, which is bit 0 in <code>b</code>.</li> </ul> <p>Thus, bits 24 to 31 in the product are bits 7 to 0 in <code>b</code>, so the eight bits finally produced are bits 7 to 0 in <code>b</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload