Skip to content

Instantly share code, notes, and snippets.

@ounziw
Created October 30, 2019 11:18
Show Gist options
  • Save ounziw/b7dcae505b1cb99d901abdf0afbb670b to your computer and use it in GitHub Desktop.
Save ounziw/b7dcae505b1cb99d901abdf0afbb670b to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace Nagoyaphp\Dokaku18;
class Dokaku18
{
public function run(string $input) : string
{
// 入力を配列に
$input_array = explode('-', $input);
$length = count($input_array);
// 各々の配列の16進→2進→配列
$data = [];
foreach ( $input_array as $var) {
$data[] = array_pad(str_split(base_convert($var, 16, 2)),-8,'0');
}
$dataout = [];
// 全部1の列は削除する
for ($i=0;$i<8;$i++) {
$is1 = 1;
for ($j = 0; $j < $length; $j++) {
$is1 *= $data[$j][$i];
}
if ($is1 == 0) {
for ($j = 0; $j < $length; $j++) {
$dataout[$j] .= $data[$j][$i];
}
}
}
$dataout2 = [];
foreach ($dataout as $var) {
$dataout2[] = str_pad(base_convert( $var,2,16),2, '0', STR_PAD_LEFT);
}
//
return implode('-', $dataout2);
//return '1f-03-00-1c-0d-0f-06';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment