PHP decbin() Help Needed

Associate
Joined
16 Aug 2004
Posts
268
I am pulling some data from an XML feed which contains a set of numbers I need to convert to binary.

Code:
<item>
<id>183904068</id>
<defindex>5041</defindex>
<inventory>2147483740</inventory>
<quantity>1</quantity>
</item>
<item>
<id>183909469</id>
<defindex>127</defindex>
<inventory>2147483651</inventory>
<quantity>1</quantity>
</item>

I'm using this code within a loop to get all the entries
Code:
<?php
   $inventory = $item->inventory;

   echo "<strong>XML</strong>: " . $inventory . "<br/>";
   echo "<strong>Binary</strong>: " . decbin($inventory);
?>

But this keeps returning

XML: 2147483740
Binary: 1111111111111111111111111111111

If I hard code a value in it works

Code:
decbin(2147483740)

It correctly displays:

XML: 2147483740
Binary: 10000000000000000000000001011100

I think it is something to do with the variable being a certian type of int, anyone have any ideas?
 
Try this:

PHP:
<?php
   $inventory = $item->inventory;

   echo "<strong>XML</strong>: " . $inventory . "<br/>";
   echo "<strong>Binary</strong>: " . decbin(floatval($inventory));
?>
 
Back
Top Bottom