diff --git a/wire/AMQPWriter.php b/wire/AMQPWriter.php
index <HASH>..<HASH> 100644
--- a/wire/AMQPWriter.php
+++ b/wire/AMQPWriter.php
@@ -27,6 +27,16 @@ class AMQPWriter
         }
 
         $res = array();
+
+        while($bytes > 0)
+        {
+            $b = bcmod($x,'256');
+            $res[] = (int)$b;
+            $x = bcdiv($x,'256');
+            $bytes--;
+        }
+        $res = array_reverse($res);
+
         for($i=0;$i<$bytes;$i++)
         {
             $b = bcmod($x,'256');
performance improvement based on <URL>