I can’t see how the first code you posted would give the expected result on any platform. The format string “%016d” says to get the input number, convert it to decimal, and pad it with up to sixteen zeroes and display it. But the output from decbin() is a string, not a number, so you can’t stick it into a decimal output format.
I tested this code:
$a = sprintf("%016b", 16384);
echo $a;
and I get
0100000000000000
The first user-contributed note on the PHP manual page for decbin() suggests the method you posted in the beginning, but I don’t see how it can work.
I’m not entirely clear on the question, however keep in mind that is_int() won’t work with strings (i.e. form input) - you need to use is_numeric() for that. However it does return valid for values that can be numbers, for example if your user enters Octal or Binary numbers as strings and, in earlier versions, hexadecimal as well.
You could write a quick function to test that all characters in a string are either digits or decimal points (and maybe commas) to do exactly what you want, if there isn’t something there already.
I have build an assembler with php of Hack Computer for a course in coursera From NAND to Tetris…
In case I want to compile an assembler program over 20000 lines to machine lang that’s zeros and ones this should take time… after run it how do browser not stop responding like do normally in 30sec , if this run takes 3-6min…? Basically do browser await like a download doing…
Maybe you could do some kind of javascript that would check every ten seconds or so. That way your browser wouldn’t be waiting with a risk of time-out.
If it’s for your use only you can tweak the memory and timeout settings on your own localhost server as you like,
I don’t know as I’d go straight to ten minutes though, I’d inch my way up.
As a general rule, needing to throw more memory and time at a script is a strong suggestion that the script needs to be better written. Though in this case I think you are probably only pushing the limits of PHP to do something it isn’t primarily meant to do, This is where others would start looking at other languages to do the work.
But anyway, as I said, if it’s only for you on your own machine, abuse it as much as you can get away with.