# Binary Clock - Time Converson Code # Mark Welker 2005 # Still Needs Hardware development and parallel port interface code # Outputs time in columns in following form # # # Hour Min Sec # # 32 32 # 16 16 16 # 8 8 8 # 4 4 4 # 2 2 2 # 1 1 1 #loop forever - its a clock after all while ($sec < 60) { #fetch time from local system ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); #============================BEGIN HOURS================================== #sets the Binary hours container ($binhour) to current time $binhour = $hour; #set null 6th bit for hours $bh32 = " "; #set 5th bit for hours if ($binhour > 15) { #5th bit true $bh16 = 1; $binhour = $binhour - 16; } else { #5th bit is false $bh16 = 0; } #set 4th bit for hours if ($binhour > 7) { #4th bit true $bh8 = 1; $binhour = $binhour - 8; } else { #4th bit false $bh8 = 0; } #set 3rd bit for hours if ($binhour > 3) { #3rd bit true $bh4 = 1; $binhour = $binhour - 4; } else { #3rd bit false $bh4 = 0; } #set 2nd bit for hours if ($binhour > 1) { #2nd bit is true $bh2 = 1; $binhour = $binhour - 2; } else { #2nd bit is false $bh2 = 0; } #set 1st bit for hours if ($binhour > 0) { #1st bit true $bh1 = 1; $binhour = $binhour - 1; } else { #1st bit is false $bh1 = 0; } #============================END OF HOURS================================== #============================BEGIN MINUTES================================== #sets the Binary minutes container ($binmin) to current time $binmin = $min; #set 6th bit for minutes if ($binmin > 31) { #6th bit true $bm32 = 1; $binmin = $binmin - 32; } else { #6th bit false $bm32 = 0; } #set 5th bit for minutes if ($binmin > 15) { #5th bit true $bm16 = 1; $binmin = $binmin - 16; } else { #5th bit is false $bm16 = 0; } #set 4th bit for minutes if ($binmin > 7) { #4th bit true $bm8 = 1; $binmin = $binmin - 8; } else { #4th bit false $bm8 = 0; } #set 3rd bit for minutes if ($binmin > 3) { #3rd bit true $bm4 = 1; $binmin = $binmin - 4; } else { #3rd bit false $bm4 = 0; } #set 2nd bit for minutes if ($binmin > 1) { #2nd bit is true $bm2 = 1; $binmin = $binmin - 2; } else { #2nd bit is false $bm2 = 0; } #set 1st bit for minutes if ($binmin > 0) { #1st bit true $bm1 = 1; $binmin = $binmin - 1; } else { #1st bit is false $bm1 = 0; } #============================END OF MINUTES================================== #============================BEGIN SECONDS================================== #sets the Binary Seconds container ($binsec) to current time $binsec = $sec; #set 6th bit for seconds if ($binsec > 31) { #6th bit true $bs32 = 1; $binsec = $binsec - 32; } else { #6th bit false $bs32 = 0; } #set 5th bit for seconds if ($binsec > 15) { #5th bit true $bs16 = 1; $binsec = $binsec - 16; } else { #5th bit is false $bs16 = 0; } #set 4th bit for seconds if ($binsec > 7) { #4th bit true $bs8 = 1; $binsec = $binsec - 8; } else { #4th bit false $bs8 = 0; } #set 3rd bit for seconds if ($binsec > 3) { #3rd bit true $bs4 = 1; $binsec = $binsec - 4; } else { #3rd bit false $bs4 = 0; } #set 2nd bit for seconds if ($binsec > 1) { #2nd bit is true $bs2 = 1; $binsec = $binsec - 2; } else { #2nd bit is false $bs2 = 0; } #set 1st bit for seconds if ($binsec > 0) { #1st bit true $bs1 = 1; $binsec = $binsec - 1; } else { #1st bit is false $bs1 = 0; } #============================END OF SECONDS================================== #============================BEGIN OUTPUT================================== print "$bh32 $bm32 $bs32 \n$bh16 $bm16 $bs16 \n$bh8 $bm8 $bs8\n$bh4 $bm4 $bs4\n$bh2 $bm2 $bs2\n$bh1 $bm1 $bs1\n\n"; #============================END OF OUTPUT================================== #wait a second and repeat sleep (1); }