fork download
  1. final class Ideone {
  2. public static final long[] toThreeBitCombinations(long e) {
  3. // get lowest 1 bit; turn off that bit;
  4. final long a = e & -e; e ^= a;
  5. final long b = e & -e; e ^= b;
  6. final long c = e & -e; e ^= c;
  7. final long d = e & -e; e ^= d;
  8.  
  9. final long ab = a | b;
  10. final long ae = a | e;
  11. final long be = b | e;
  12. final long cd = c | d;
  13.  
  14. return new long[] { ab | c, ab | d, a | cd, b | cd, ab | e,
  15. ae | c, be | c, ae | d, be | d, cd | e
  16. };
  17. }
  18.  
  19. public static void main(final String[] args) {
  20. for (final long combo : toThreeBitCombinations(0b101010101)) {
  21. System.out.printf("%9s\n", Long.toBinaryString(combo));
  22. }
  23. }
  24. }
Success #stdin #stdout 0.06s 27988KB
stdin
Standard input is empty
stdout
    10101
  1000101
  1010001
  1010100
100000101
100010001
100010100
101000001
101000100
101010000