$average ? 1 : 0; $one = $one << 1; } return $binary; } public function hex($binary) { if (strlen($binary) !== self::SIZE * self::SIZE) { throw new Exception('Binary length must be ' . self::SIZE * self::SIZE); } $hex = ''; foreach (str_split($binary, 4) as $binary) { $hex .= dechex(bindec($binary)); } return $hex; } }