Quelltext der Datei: http://www.michaelster.ch/lernen/__new__zahlensystem_converter.php

Dateigrösse: 3.74 kb

[Anzeige mit Zeilennummern]


<?php
$sys = isset($_POST['system']) ? $_POST['system'] : false;
$sys = $sys ? $sys : 2;
$sys_js = $sys ? $sys-2 : 0;

$zzz = isset($_POST['zzz']) && $_POST['zzz']!='' ? $_POST['zzz'] : false;
$zzz = preg_replace('/\'/', '', $zzz);
$zzz = preg_replace('/ /', '', $zzz);
settype($zzz, "double");
//settype($zzz, "int");
$zzz = intval(round($zzz));


if($_POST['hide']=='ok' && $zzz)
{
    echo '<style type="text/css">input.send{display:none !important;}</style>'; 
    $newSys  = powExp($zzz, $sys);
    $result  = '<div class="result"><b>' . number_format($zzz, 0, ".", "'") . '</b> im <b>' . $sys . 'er-System</b> = <b>' . $newSys . '</b>';
    $result .= '<div class="weiter"><a href="./?nid=seven" title="n&auml;chste Zahl">&raquo;&raquo;&raquo;</a></div>';
    $result .= '</div>';
}

function powExp($zahl, $system)
{
    for($i = 0; $i <= $zahl; $i++)
    {
        if($zahl < pow($system, $i))
        {
            $exp = ($i-1);
            return systemChange($exp, $zahl, $system);
        }
    }
}

function systemChange($exp, $zahl, $system)
{
    $result = '';
    
    for($i = $exp; $i >= 0; $i--)
    {
        if(($zahl / pow($system, $i)) >= 1)
        {
            $faktor  = floor($zahl / pow($system, $i));
            $zahl      = ($zahl - ($faktor * pow($system, $i)));
            $result .= $faktor . '&nbsp;';
        }
        else
        {
            $zahl     = $zahl;
            $result .= '0' . '&nbsp;';
        }
    }
    
    return $result;
}

?>


<style type="text/css">
h1        { font-family:palatino,calibri,verdana,sans-serif; font-weight:bolder; font-size:20pt !important; margin:0; padding-bottom:2em; } 
.result    { background-color:transparent; color:#333; padding:1em; border:1pt solid #333; border-radius:5pt; min-width:25em; box-shadow: 2pt 2pt 4pt crimson; font-family:verdana,calibri,sans-serif; font-size:11pt !important; display:inline-block; }
.result .weiter    { float:right; font-weight:bold; }
.result .weiter    a { text-decoration:none; color:#000; padding-left:2em; }
.result .weiter    a:hover { text-decoration:overline; color:crimson; }
.content p         { padding:5px 0; font-size:11pt !important; }
.content form            { font-family:verdana,calibri,sans-serif; font-size:11pt !important; }
.content input, select    { padding:5pt 5pt !important; border:1pt solid #333; font-family:verdana,calibri,sans-serif; font-size:11pt !important; width:100pt; }
.content input.send         { padding:5px 15pt; border-radius:3pt; font-size:11pt !important; font-weight:bold; display:inline; }
.content input:focus, .content input:hover,
.content select:focus, .content select:hover { background-color:#fff; }
</style>

<h1>Zahlensystem-Umrechner</h1>

<div class="content">
<form method="post" action="./?nid=seven" name="converter">
  <p>Deine Zahl im 10er-System:</p>
    <input type="text" name="zzz" size="10" maxlength="7" value="<?php echo isset($_POST['hide']) ? number_format($zzz, 0, ",", "'") : $zzz; ?>" />
  <br>
  <br>
  <p>umrechnen ins:</p>
    <select name="system" size="1">
                        <option value="2">2er-System</option>
                        <option value="3">3er-System</option>
                        <option value="4">4er-System</option>
                        <option value="5">5er-System</option>
                        <option value="6">6er-System</option>
                        <option value="7">7er-System</option>
                        <option value="8">8er-System</option>
                        <option value="9">9er-System</option>
    </select>
  <br>
  <br>
  <hr align="left" style="width:28em; color:transparent;" />
  <br>
    <input type="hidden" name="hide" value="ok" />
    <input type="submit" name="schicken" value="macht ..." class="send" onfocus="if(this.blur)this.blur();" />
</form>

<?php
echo $result;
?>

</div>

<script type="text/javascript">
    document.converter.zzz.select();
    document.converter.system.selectedIndex=<?php echo $sys_js; ?>;
</script>