creation of integers from raw representation
<p>I try to create integers from raw-data that I read from '/dev/urandom'. But I do not know how to convert to an integer.</p>

<pre><code>&lt;?php

//////////////////////////////////////////////////////////////////////////////

function base62_encode($val, $base=62, $chars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
   if(!isset($base))
        $base = strlen($chars);
    $str = '';
    do {
        $m = bcmod($val, $base);
        $str = $chars[$m] . $str;
        $val = bcdiv(bcsub($val, $m), $base);
    } while(bccomp($val,0)&gt;0);
    return $str;
}

//////////////////////////////////////////////////////////////////////////////

$file = fopen('/dev/urandom', 'rb');
if ( !$file ) {
   throw new Exception('Error!');
} else {
    $binary = fread($file, 4); // 4 bytes == 32 bits
   fclose($file);
   $dec = (int)$binary;
    $base62 = base62_encode($dec);

   fprintf(STDOUT, "dec:%d, %s\n", $dec, $base62);
}

//////////////////////////////////////////////////////////////////////////////

?&gt;
</code></pre>

<p>As output I get: "dec:0, 0"</p>

<p>You can test code <a href="http://liveworkspace.org/code/14DJhT%242" rel="nofollow">here</a>.</p>
