summaryrefslogtreecommitdiff
path: root/reference/C/CONCEPT/JavaSim.html
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2008-01-27 11:37:44 +0100
committerTobias Klauser <tklauser@xenon.tklauser.home>2008-01-27 11:37:44 +0100
commit7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch)
treeb1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/CONCEPT/JavaSim.html
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/CONCEPT/JavaSim.html')
-rw-r--r--reference/C/CONCEPT/JavaSim.html254
1 files changed, 254 insertions, 0 deletions
diff --git a/reference/C/CONCEPT/JavaSim.html b/reference/C/CONCEPT/JavaSim.html
new file mode 100644
index 0000000..416e666
--- /dev/null
+++ b/reference/C/CONCEPT/JavaSim.html
@@ -0,0 +1,254 @@
+<title>Bit Manipulation Simulator</title>
+
+<head>
+<script language="JavaScript">
+
+function BitWise(form)
+{
+ // ... Convert the supplied hex numbers to decimal.
+
+ var Left = HexToDec(form.Left.value);
+ var Right = HexToDec(form.Right.value);
+
+ // ... Get the operation symbol (& | >> <<);
+
+ var Operation = form.Operation[form.Operation.options.selectedIndex].value;
+
+ Oper = Operation;
+
+ // ... Do the calculation in decimal.
+
+ var DecAns = eval(Left + Operation + Right);
+
+ // ... convert the answer back to Hex format.
+
+ var BinAns = DecToBin(DecAns);
+
+ form.Ans.value = BinToHex(BinAns);
+
+ // Butify the inputs.
+
+ BinAns = DecToBin(Left);
+
+ form.Left.value = BinToHex(BinAns);
+
+ BinAns = DecToBin(Right);
+
+ form.Right.value = BinToHex(BinAns);
+
+ // refresh the screen so the table can display the updated values.
+
+ history.go(0);
+}
+
+function HexToDec(Hex)
+{
+ return(parseInt(Hex, 16));
+}
+
+function DecToBin(Decimal)
+{
+ var Index = 128; /* Just look at the 8
+ * low order bits */
+ var Binary ="";
+
+ while(Index > 0)
+ {
+ if (Index == 8) Binary += " "; /* Put a space between the */
+ // Bytes */
+
+ if((Decimal % Index) != Decimal)
+ {
+ Binary += "1";
+ Decimal -= Index;
+ }
+ else
+ {
+ Binary += "0";
+ }
+ Index /= 2;
+
+ // Bodge...
+
+ if (Index == 0.5) Index = 0;
+ }
+ return(Binary)
+}
+
+function BinToHex(Binary)
+{
+ var Left = Binary.substring(0,4);
+ Left = BinToHexConv(Left);
+ var Right = Binary.substring(5,9);
+ Right = BinToHexConv(Right);
+
+return(Left+Right);
+}
+
+function BinToHexConv(Binary)
+{
+ this["0000"] = "0";
+ this["0001"] = "1";
+ this["0010"] = "2";
+ this["0011"] = "3";
+ this["0100"] = "4";
+ this["0101"] = "5";
+ this["0110"] = "6";
+ this["0111"] = "7";
+ this["1000"] = "8";
+ this["1001"] = "9";
+ this["1010"] = "A";
+ this["1011"] = "B";
+ this["1100"] = "C";
+ this["1101"] = "D";
+ this["1110"] = "E";
+ this["1111"] = "F";
+
+ return(this[Binary])
+}
+
+</script>
+</head>
+
+<body bgcolor="#ffffcc">
+<hr>
+<center>
+<h1>Bit Manipulation Simulator</h1>
+</center>
+<hr>
+
+This page requires JavaScript support to test the various bitwise operators.
+If you do not have JavaScript available, you can try the CGI supported
+simulator.
+<p>
+
+<hr>
+<p>
+<center>
+<form name="form1">
+Enter the Hex values and select an operator, then press the 'Execute'
+button to see the results.
+<p>
+
+<input type="text" value="00" name="Left" size=4>
+<select name="Operation">
+<option value=" & "> &
+<option value=" | "> |
+<option value=" << "> <<
+<option value=" >> "> >>
+</select>
+
+<input type="text" value="00" name="Right" size=4>
+<input type="Button" value="Execute" name="Ex" onclick="BitWise(this.form)">
+<input type="text" value="00" name="Ans" size=4>
+</form>
+</center>
+
+<center>
+<table border=2 bgcolor="ivory">
+<tr align=center>
+
+<td>Hex</td>
+
+<td>Binary</td>
+
+<td>Decimal</td>
+</tr>
+
+<tr><td>
+<h3>
+<script>
+
+// ... When the document is loaded, this is true
+// ... and the default values are set.
+
+if (document.form1.Operation.options.selectedIndex == -1)
+{
+ document.form1.Operation.options.selectedIndex = 0;
+ document.form1.Left.value = 00;
+ document.form1.Right.value = 00;
+ document.form1.Ans.value = 00;
+}
+
+document.writeln("<pre>");
+document.writeln(" ");
+document.writeln(" " + document.form1.Left.value + " ");
+document.write (" " + document.form1.Operation[document.form1.Operation.options.selectedIndex].value);
+document.writeln(document.form1.Right.value);
+document.writeln(" --");
+document.writeln(" " + document.form1.Right.value);
+// document.writeln(" " + document.form1.Operation[1].value);
+document.writeln("</pre>");
+</script>
+</h3>
+</td>
+
+<td>
+<h3>
+<script>
+document.writeln("<pre>");
+document.writeln(" ");
+document.writeln(" " + DecToBin(HexToDec(document.form1.Left.value)) + " ");
+document.write (" " + document.form1.Operation[document.form1.Operation.options.selectedIndex].value);
+document.writeln(DecToBin(HexToDec(document.form1.Right.value)));
+document.writeln(" ---------");
+document.writeln(" " + DecToBin(HexToDec(document.form1.Ans.value)));
+document.writeln("</pre>");
+</script>
+</h3>
+</td>
+
+<td>
+<h3>
+<script>
+document.writeln("<pre>");
+document.writeln(" ");
+document.writeln(" " + HexToDec(document.form1.Left.value) + " ");
+document.write (" " + document.form1.Operation[document.form1.Operation.options.selectedIndex].value);
+document.writeln(HexToDec(document.form1.Right.value));
+document.writeln(" --");
+document.writeln(" " + HexToDec(document.form1.Ans.value));
+document.writeln("</pre>");
+</script>
+</h3>
+</td></tr>
+</table>
+</center>
+<p>
+
+<font color=red>
+Sections of this page controlled by 'JavaScript' cannot be printed.
+</font>
+<p>
+<hr>
+<h2>See Also:</h2>
+<img src=../../GRAPHICS/whiteball.gif>
+<a href=../CONCEPT/bitwise.html>Bitwise Operators</a>.
+<P>
+<hr>
+<p>
+<center>
+<table border=2 width=80% bgcolor=ivory>
+<tr align=center>
+<td width=25%>
+<a href="../cref.html">Top</a>
+</td><td width=25%>
+<a href="../master_index.html">Master Index</a>
+</td><td width=25%>
+<a href="../SYNTAX/keywords.html">Keywords</a>
+</td><td width=25%>
+<a href="../FUNCTIONS/funcref.htm">Functions</a>
+</td>
+</tr>
+</table>
+</center>
+<p>
+<hr>
+<address>Martin Leslie
+<script language="JavaScript">
+<!-- //
+document.write(document.lastModified);
+// -->
+</script>
+</address>
+</body