1

I'm programming a web app where you put a hex value in a field and the app give you the details of which bit are up. But I'm facing a problem if a do:

base_convert(value,16,2)

with a 6 byte value I get the right bit correspondence, but if I do it again with 7 or more byte value I get a string that is not the right bit correspondence. I don't know how to fix this problem since it's a PHP function. Is there any alternative to this function in PHP?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • 1
    Have you read the documentation carefully? Warning base_convert() may lose precision on large numbers due to properties related to the internal "double" or "float" type used. Please see the Floating point numbers section in the manual for more specific information and limitations. – Honk der Hase Mar 15 '19 at 08:15
  • Yeah i noticed that , but my question was more about solutions or alternative to this problem. – Maxime Gouet Mar 15 '19 at 08:21

2 Answers2

1

You should work byte per byte instead of putting right away the full value in the base_convert() function.

Xilamax
  • 30
  • 5
0

please try this .

echo base_convert('value',16,2); or

$test='value'; echo base_convert($test,16,2);

output: 10101110

ref: http://php.net/manual/en/function.base-convert.php