Is it possible to print a fixed length binary string in perl of binary characters? What I have so far, is this:
printf(OUTFILE "%b\n", $nextToken);
But this only prints out relevant bits. i.e. If $nextToken = 3, then the string only prints out:
11
What I want it to print out, is:
000011
Is there an easy way to get perl to print out the extra 4 characters to make this a 6-character long binary string?
Check out the docs for sprintf. The very first example shows how to add leading 0's
printf(OUTFILE "%06b\n", $nextToken);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句