Package COM. SDO. tradinghub. domain; </P> <p> public class bitsorttest {<br/> Private Static final int bitsperword = 32; // integer digits <br/> Private Static final int shift = 5; <br/> Private Static final int mask = 0x1f; // 5-bit masking 0b11111 <br/> Private Static final int n = 10000000; <br/> // simulate a bit array with an int array, total (1 + N/bitsperword) * The bitsperword bit is sufficient to accommodate n <br/> Private Static int [] A = new int [(1 + N/bitsperword)]; </P> <p> P Ublic static void main (string [] ARGs) {<br/> bitsort (New int [] {1,100, 2, 10000,999 9, 4567,789 02 }); <br/>}</P> <p> Public static void bitsort (INT [] array) {<br/> for (INT I = 0; I <N; I ++) <br/> CLR (I); // all bits in the array are 0 <br/> for (INT I = 0; I <array. length; I ++) <br/> set (array [I]); // Phase 2 <br/> for (INT I = 0; I <N; I ++) <br/> If (test (I) <br/> system. out. println (I); <br/>}</P> <p> // set & Amp; mask) bit is 1, that is, the I-bit of the bit array is 1 <br/> Public static void set (int I) {<br/> A [I> shift] | = (1 <(I & Mask )); <br/>}</P> <p> // set the position (I & Mask) of a [I> shift] to 0, that is, the I-bit of the bit array is 0 <br/> Public static void CLR (int I) {<br/> A [I> shift] & = ~ (1 <(I & Mask )); <br/>}</P> <p> // test whether the I-th bit of the bit array is 1 <br/> Public static Boolean test (int I) {<br/> return (A [I> shift] & (1 <(I & Mask) = (1 <(I & Mask )); <br/>}< br/>}