Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thinking in bits in not that hard, you just need to convert, in your head, all the values into bits and work on them a bit at a time. That sounds hard but it <em>does</em> get easier over time. A good first step is to start thinking of them as hex digits (4 bits at a time).</p> <p>For example, let's say <code>a</code> is 0x13, <code>b</code> is 0x22 and <code>mask</code> is 0x0f:</p> <pre><code>a : 0x13 : 0001 0011 b : 0x22 : 0010 0010 --------------------------------- a^b : 0x31 : 0011 0001 mask : 0x0f : 0000 1111 --------------------------------- (a^b)&amp;mask : 0x01 : 0000 0001 a : 0x13 : 0001 0011 --------------------------------- a^((a^b)&amp;mask) : 0x12 : 0001 0010 </code></pre> <p>This particular example is a way to combine the top four bits of <code>a</code> with the bottom 4 bits of <code>b</code> (the mask decides which bits come from <code>a</code> and <code>b</code>.</p> <p>As the site says, it's an optimization of <code>(a &amp; ~mask) | (b &amp; mask)</code>:</p> <pre><code>a : 0x13 : 0001 0011 ~mask : 0xf0 : 1111 0000 --------------------------------- a &amp; ~mask : 0x10 : 0001 0000 b : 0x22 : 0010 0010 mask : 0x0f : 0000 1111 --------------------------------- b &amp; mask : 0x20 : 0000 0010 a &amp; ~mask : 0x10 : 0001 0000 b &amp; mask : 0x20 : 0000 0010 --------------------------------- (a &amp; ~mask) | : 0x12 : 0001 0010 (b &amp; mask) </code></pre> <p><em>Aside:</em> I wouldn't be overly concerned about not understanding something on that page you linked to. There's some serious "black magic" going on there. If you really want to understand bit fiddling, start with unoptimized ways of doing it.</p>
    singulars
    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. This table or related slice is empty.
    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