$decimal = 10;
$binary = decbin($decimal);
echo $binary; // 輸出:1010
$decimal = 10;
$binary = decbin($decimal);
$binary = str_pad($binary, 8, '0', STR_PAD_LEFT);
echo $binary; // 輸出:00001010
$decimal = 10;
$binary = decbin($decimal);
$binary = str_pad($binary, 8, '0', STR_PAD_LEFT);
$part = substr($binary, 2, 4);
echo $part; // 輸出:0010
$decimal = 10;
$binary = decbin($decimal);
$binary = str_pad($binary, 8, '0', STR_PAD_LEFT);
$replaced = str_replace('0', '1', $binary);
echo $replaced; // 輸出:11111010
這些技巧可以幫助您在處理二進制字符串時更加靈活和高效。