Created
February 5, 2013 19:04
-
-
Save hertzsprung/4716775 to your computer and use it in GitHub Desktop.
Silly bit twiddling for berlin clock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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