in reply to Re: Converting negative number to binary with specific width
in thread Converting negative number to binary with specific width
If you insist on strings, substr is still probably easier than pack.
substr(sprintf("%0*b", $bits, $num), -$bits)
|
|---|