Skip to content

Instantly share code, notes, and snippets.

@kezzyhko
Created November 5, 2020 18:16
Show Gist options
  • Select an option

  • Save kezzyhko/5d3a084c7e14c4e377852dfb0d7840cd to your computer and use it in GitHub Desktop.

Select an option

Save kezzyhko/5d3a084c7e14c4e377852dfb0d7840cd to your computer and use it in GitHub Desktop.
Script, which checks parity bits, decodes binary to ascii, and puts * for corrupted bytes | http://sandbox.onlinephpfunctions.com/code/5ee7ce353ca66583ab52b6e21b5e4f4326a8608d
<?php
// Available for test at http://sandbox.onlinephpfunctions.com/code/5ee7ce353ca66583ab52b6e21b5e4f4326a8608d
$ins = [
'01010011 01001111 11001100 01000001 01010010 11001001 01010011',
'11010111 11001001 11001110 01000100 01001111 11010111 01010011',
'01000111 01001111 11001111 11000111 11001100 11000101',
'11011001 01000001 01001110 11000100 11000101 11011000',
'01000001 11001101 01000001 01011010 11001111 11001110'
];
echo "---\n";
foreach ($ins as $in) {
foreach (explode(' ', $in) as $n) {
echo $n;
if (array_sum($n = str_split($n))%2 === 0) {
array_shift($n);
$n = implode('', $n);
echo ' = ' . dechex(bindec($n)) . ' ---> ' . chr(bindec($n));
}
else echo ' --------> *';
echo "\n";
}
echo "---\n";
}
<?php
$ins = [
'01010011 01001111 11001100 01000001 01010010 11001001 01010011',
'11010111 11001001 11001110 01000100 01001111 11010111 01010011',
'01000111 01001111 11001111 11000111 11001100 11000101',
'11011001 01000001 01001110 11000100 11000101 11011000',
'01000001 11001101 01000001 01011010 11001111 11001110'
];
echo '<hr>';
foreach ($ins as $in) {
foreach (explode(' ', $in) as $n) {
echo $n;
if (array_sum($n = str_split($n))%2 === 0) {
array_shift($n);
$n = implode('', $n);
echo ' = ' . dechex(bindec($n)) . ' ---> ' . chr(bindec($n));
}
else echo ' --------> 0';
echo '<br>';
}
echo '<hr>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment