I was wondering if there is an easy way to display 8 bit bytes (or char) in PHP.
For example, for ASCII encoding, the character "0" should return 0011 0000
Thanks for your input!
This should complete the task:
$bin = decbin(ord($char)); $bin = str_pad($bin, 8, 0, STR_PAD_LEFT);
You can use bitwise operators to do this.
$a='C'; for ($i=0; $i<8; $i++) { var_dump((ord($a) & (1<<$i))>>$i); }
Output:
int(1) int(1) int(0) int(0) int(0) int(0) int(1) int(0)
Another solution, including a space between four digits:
$char = 0; echo chunk_split(sprintf('%08b', ord($char)), 4, ' ');
Source: https://habr.com/ru/post/1482852/More articles:Getting the Handbrake Encoder to Work - c #Angular select with ng-option sends index instead of value when submitting form - angularjsCreate OpenCV in Visual Studio 2012 with CUDA - opencvApplication with privileges for Firefox OS: permission to access the document object of a new window object - javascriptAndroid AlertDialog.Builder setSingleChoiceItems with custom cell style - androidHow to hide the notification bar, but allow drag and drop on top? - androidUpdate time for AlarmManager (Android) - androidis there any way to distinguish stderr in console release? - stderrHow to prevent backspace with readline readable (readable stdin) - node.jsHow to specify COMSTR for Command Builder in 'scons' - pythonAll Articles