I have the following Python code snippet and I am trying to convert this to PHP. This actually generates Gray Code.
Python:
x,n=0,1<<int(sys.argv[1])
while n>x:print bin(n+x^x/2)[3:];x+=1
PHP
<?php
fscanf(STDIN, "%d\n", $number);
$x=0; $n=1<<$number
while($n > $x) {
print decbin($n+$x^$x/2);
x++;
}
Now, in the Python code there is a code at 2nd line inside the while loop:
bin(n+x^x/2)[3:];
I have converted this line to:
decbin($n+$x^$x/2);
but, what should be this: [3:]
in PHP? And am I right for as far as I converted?