Vorlesung Informationstechnologie

Universität Wien/Fakultät für Wirtschaftswissenschaften

Eine binäre Uhr

Unter Nerd sehr verbreitet ist eine Uhr mit binärer Darstellung. Hier ein kleines Beispiel in Javascript.

Online: eine binäre Uhr

Sourcecode (Beispiel):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="de-at" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<style type="text/css">
.auto-style1 {
border: 4px solid #000000;
}

input {
color: black;
text-align: center;
}

textarea {
font-weight: 900;
overflow: hidden;
color: red;
text-align: center;
}
</style>
<script language="javascript">

function zeiter()
{
timer = setInterval("updateTime();", 1000);
}

//pads left
String.prototype.lpad = function(padString, length) {
var str = this;
while (str.length < length)
str = padString + str;
return str;
}

function farbwechsel (bini,reihe)
{
for(i=3;i>=0;i--)
{
zelli = "h"+reihe.toString()+(i+1);
if (bini.substr(i,1) == "0")
document.getElementById(zelli).bgColor = "white"
else
document.getElementById(zelli).bgColor = "red";
}
}

function updateTime()
{
d= new Date();
t= d.getHours();
m= d.getMinutes();
s= d.getSeconds();
t2 = t%10;
t1 = (t-t2)/10;
m2 = m%10;
m1 = (m-m2)/10;
s2 = s%10;
s1 = (s-s2)/10;
document.getElementById("Text1").value = t.toString(10).lpad("0",2)+":"+m.toString(10).lpad("0",2)+":"+s.toString(10).lpad("0",2);

farbwechsel(t1.toString(2).lpad("0",4),1);
farbwechsel(t2.toString(2).lpad("0",4),2);
farbwechsel(m1.toString(2).lpad("0",4),3);
farbwechsel(m2.toString(2).lpad("0",4),4);
farbwechsel(s1.toString(2).lpad("0",4),5);
farbwechsel(s2.toString(2).lpad("0",4),6);

}

</script>
<title>Binäre Uhr</title>
</head>

<body onload="zeiter()" bgcolor="black">

<table class="auto-style1" style="width: 240px">
<tr>
<td id="h11">&nbsp;</td>
<td id="h21">&nbsp;</td>
<td id="h31">&nbsp;</td>
<td id="h41">&nbsp;</td>
<td id="h51">&nbsp;</td>
<td id="h61">&nbsp;</td>
</tr>
<tr>
<td id="h12">&nbsp;</td>
<td id="h22">&nbsp;</td>
<td id="h32">&nbsp;</td>
<td id="h42">&nbsp;</td>
<td id="h52">&nbsp;</td>
<td id="h62">&nbsp;</td>
</tr>
<tr>
<td id="h13">&nbsp;</td>
<td id="h23">&nbsp;</td>
<td id="h33">&nbsp;</td>
<td id="h43">&nbsp;</td>
<td id="h53">&nbsp;</td>
<td id="h63">&nbsp;</td>
</tr>
<tr>
<td id="h14">&nbsp;</td>
<td id="h24">&nbsp;</td>
<td id="h34">&nbsp;</td>
<td id="h44">&nbsp;</td>
<td id="h54">&nbsp;</td>
<td id="h64">&nbsp;</td>
</tr>
</table>

<p><form method="post" action="">
<input id="Text1" name="Text1" type="text" size="34" />
</form></p>
</body>

</html>