PHP无法计算(二进制十六进制怪异)?

In Perl I have code that is working correctly:

print unpack('B*','10071C2');

returns 00110001001100000011000000110111001100010100001100110010

The code ported to PHP using GMP:

function gmp_convert($num, $base_a, $base_b)
{
        return gmp_strval ( gmp_init($num, $base_a), $base_b );
}
$test = "10071C2";
$testb=gmp_convert($test, 16, 2);

produces 10000000110110001110000101001101111110110001101110000111

I thought it might be byte order, however if I use b* instead in Perl it still produces something else:

PHP---10000000110110001110000101001101111110110001101110000111
PERL--10001100000011000000110011101100100011001100001001001100

I simply do not understand this, can anyone help?

Your Perl and PHP implementations are doing entirely separate things.

The Perl code is converting each of the characters from the input string into the binary representation of the ASCII code for that character. For instance, the first character ("1") gets converted into "00110001" which is equal to decimal 49, the ASCII code for the character 1.

Your PHP code successfully converts the hex number represented in string form into an equivalent binary representation in string form.