Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf8">
- <title>Projekt do LO</title>
- </head>
- <body>
- <h1>Projekt do LO na 16 bitů</h1>
- <?php
- function doplnek($cislo,$otocit = false)
- {
- if($otocit){
- $cislo *= -1;
- }
- if($cislo < 0)
- return 65536 - abs($cislo);
- return $cislo;
- }
- if(!empty($_POST)){
- $q = intval($_POST["q"]);
- $a = round(floatval(str_replace(",", ".", $_POST["a"])) * pow(2, $q));
- $b = round(floatval(str_replace(",", ".", $_POST["b"])) * pow(2, $q));
- if($q == 0 or $a == 0 or $b == 0){
- echo "error";
- }else{
- $aD = doplnek($a);
- $bD = doplnek($b);
- $aH = strtoupper(dechex($aD));
- $bH = strtoupper(dechex($bD));
- echo "<strong>Číslo A:</strong> (".str_pad($aH, 4,'0',STR_PAD_LEFT).")H";
- echo "<br /><strong>Číslo B:</strong> (".str_pad($bH, 4,'0',STR_PAD_LEFT).")H";
- $soucet = hexdec($aH) + hexdec($bH);
- $rozdil = hexdec($aH) + doplnek(hexdec($bH),true);
- $sH = strtoupper(dechex($soucet));
- $rH = strtoupper(dechex($rozdil));
- if(strlen($sH) > 4)
- $sH = substr($sH,strlen($sH)-4,4);
- if(strlen($rH) > 4)
- $rH = substr($rH,strlen($rH)-4,4);
- echo "<br /><strong>Součet:</strong> (".str_pad($sH, 4,'0',STR_PAD_LEFT).")H";
- echo "<br /><strong>Rozdíl:</strong> (".str_pad($rH, 4,'0',STR_PAD_LEFT).")H";
- $sD = hexdec($sH);
- $rD = hexdec($rH);
- if($sD >= 32768)
- $sD -= 65536;
- if($rD >= 32768)
- $rD -= 65536;
- $sD = $sD / pow(2, $q);
- $rD = $rD / pow(2, $q);
- echo "<br /><strong>Součet:</strong> ".round($sD,2);
- echo "<br /><strong>Rozdíl:</strong> ".round($rD,2);
- }
- }
- ?>
- <form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
- <p><strong>Formát:</strong> Q<input type="text" name="w" size="1" value="<?php echo $_POST["w"];?>"/>
- .<input type="text" name="q" size="1" value="<?php echo $q;?>"/></p>
- <p><strong>Číslo A:</strong> <input type="text" name="a" value="<?php echo $_POST["a"];?>" /></p>
- <p><strong>Číslo B:</strong> <input type="text" name="b" value="<?php echo $_POST["b"];?>" /></p>
- <p><input type="submit" value="Počítej!" /></p>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement