4 ms·
The "stuff" assigns an integer value to the char. 'b' - 'a' = 1, for example. This assigns each char a unique integer value. By shifting 1 up that many times, y
by dahfizz 4y ago
The "stuff" assigns an integer value to the char. 'b' - 'a' = 1, for example. This assigns each char a unique integer value. By shifting 1 up that many times, you assign a unique bit position to each char.
- alanning 4y agoFor those new to bitshifting, here are the results of the "stuff" operation that @dahfizz describes: 'a' - 'a' = 0, so take 1 and shift it left 0 times: 00000000000000000000000000000001 = 'a' 'b' - 'a' = 1, so take 1 and shift it left 1 time: 00000000000000000000000000000010 = 'b' 'c' - 'a' = 2, so take 1 and shift it left 2 times: 00000000000000000000000000000100 = 'c' (I'm not sure why the post's author chose to use 10000000000000000000000000000000 as their example for 'a' rather than the above which IIUC is how the code actually works.)