Skip to content

Instantly share code, notes, and snippets.

@hertzsprung
Created February 5, 2013 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hertzsprung/4716775 to your computer and use it in GitHub Desktop.
Save hertzsprung/4716775 to your computer and use it in GitHub Desktop.
Silly bit twiddling for berlin clock
public class BerlinClock {
public static String[] print(Time time) {
char seconds = (char) (89 - 10 * (time.second & 1));
char our = (char) (79 + 3 * (time.hour & 1));
/*
000 00000000 00000000 00000000 00000000
001 00000000 00000000 00000000 10000000
010 00000000 00000000 10000000 10000000
011 00000000 10000000 10000000 10000000
100 10000000 10000000 10000000 10000000
*/
int mask = (0x03030303 >>> (4-time.hour)*4) >>> (4-time.hour)*4;
mask += 0x4f4f4f4f;
mask = ((mask >> 8) & 0x00ff00ff) | ((mask & 0x00ff00ff) << 8);
mask = ((mask >> 16) & 0xffff) | ((mask & 0xffff) << 16);
ByteBuffer byteb = ByteBuffer.allocate(4);
IntBuffer intb = byteb.asIntBuffer();
intb.put(mask);
return new String[]{""+seconds, "OOOO", new String(byteb.array()),"OOOOOOOOOOO","OOOO"};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment