Binary Clock

Ever think telling the time is just a little bit too easy? Why not throw in some maths to make it a mini test every time you check the clock?

Here's a small Java program I wrote that displays the time using binary digits. It'll be second (get it?)  nature in no time!

import java.util.*;
/**
 *
 * @author D. Duncombe
 */
public class Main {
   
   
   
  /** Creates a new instance of Main */
  public Main() {
  }
   
  /**
  * @param args the command line arguments
  */
  public static void main(String[] args) {
   
  System.out.println("*************************");
  System.out.println("*** Binary Clock V1.0 ***");
  System.out.println("***    D. Duncombe    ***");
  System.out.println("*************************");
   
  while (1 == 1)
  {
   
  Calendar cal = Calendar.getInstance();
  int secondValue1 = cal.get(cal.SECOND);
  int secondValue2 = secondValue1;
   
  int minuteValue = cal.get(cal.MINUTE);
  int hourValue = cal.get(cal.HOUR_OF_DAY);
   
  String secondString = Integer.toBinaryString(secondValue1);
  String minuteString = Integer.toBinaryString(minuteValue);
  String hourString = Integer.toBinaryString(hourValue);

  System.out.println(hourString + " : " + minuteString 
  + " : " + secondString);
   
  while (secondValue2 == secondValue1)
  {
  cal = Calendar.getInstance();
  secondValue1 = cal.get(cal.SECOND);
  }
  }
   
  }
   
}



Comments

Popular posts from this blog

Never one to pass up a challenge...

Learning C++ (or programming Conway's Game of Life)

Binary Combination Lock