Dinesh Kumar February 2016

10 digit decimal to binary conversion not works

I am facing issue while I convert 10 digit decimal to binary. When I convert up to 9 digits it perfectly works at the same time when I use decbin() function for 10 digit long it doesn't work.

For an example when I convert decimal to binary using decbin() this function with any inputs up to 9 digits then I will get proper out. When I use 10 digit decimal I getting same output (1111111111111111111111111111111) for numbers between 2200000000 - 9999999999 as input.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>test</title>
</head>
<body>
<?php
$num = $_GET[n];
$bin = decbin($num);    // Decimal to binary
?>
<table>
<tr><td>Number:</td><td><?php echo $num; ?></td></tr>
<tr><td>Binary:</td><td><a href='binary.php?b=<?php echo $bin; ?>'><?php echo $bin; ?></a></td></tr>
</table>
</body>
</html>

When I visit number.php?n=2200000845 it shows 1111111111111111111111111111111 as result.

Anyone please solve this problem..

Answers


AnkiiG February 2016

You are using $num for $bin2 also. Change

$bin2 = decbin($num);

to

$bin2 = decbin($num2);


MrRP February 2016

On 32-bit system the maximum decimal number is: 4294967295

Check it: http://php.net/manual/en/function.decbin.php

Post Status

Asked in February 2016
Viewed 1,579 times
Voted 12
Answered 2 times

Search




Leave an answer