Home Ask Login Register

Developers Planet

Your answer is one click away!

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>
<meta charset="UTF-8" />
$num = $_GET[n];
$bin = decbin($num);    // Decimal to binary
<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>

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

Anyone please solve this problem..


AnkiiG February 2016

You are using $num for $bin2 also. Change

$bin2 = decbin($num);


$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


Leave an answer

Quote of the day: live life