Bitwise less-than

Here and after we denote as [a]B[a]_B the bitstring representation (i.e. sequence of shared bits correspondings to the binary decomposition of aa). Our purpose is, for two bitstrings, to compute the bit [a<Bb][a <_B b].

  1. [ci]=[ai][bi]=[ai]+[bi]2[aibi][c_i] = [a_i] \oplus [b_i] = [a_i] + [b_i] - 2[a_i b_i]
  2. [di]=l1s=ics[d_i] = \underset{s=i}{\overset{l-1}{\vee}}c_s // using prefix OR.
  3. [ei]=[di][di+1][e_i] = [d_i] - [d_{i+1}] for i<li < l, [el1]=[dl1][e_{l-1}] = [d_{l-1}]
  4. [a<Bb]=l1i=0[eibi][a <_B b] = \underset{i=0}{\overset{l-1}\sum} [e_i b_i]

It is easy to see by direct inspection: di=0d_i = 0 up to (counting from the most significant bit, l1l-1) the first different bit, and from it equals 11. Therefore, eie_i equals 11 exactly in the the most significant different bit, and, hence, l1i=0[eibi]\underset{i=0}{\overset{l-1}\sum} [e_i b_i] computes 00 if this bit is 00 in bb, and 11 if this bit is 11 in bb. The only remaining case is if a=ba = b, in which case all the variables in these equations are 00, as it should be.

results matching ""

    No results matching ""