The stupid question is the question not asked | |
PerlMonks |
Re: Converting negative number to binary with specific widthby RichardK (Parson) |
on Nov 03, 2015 at 00:45 UTC ( [id://1146780]=note: print w/replies, xml ) | Need Help?? |
The problem is that the b format is for unsigned integers only, so your -1 gets turned into an unsigned int and printing that overflows your field width, giving you lots of ones.The help for sprintf says :-
BTW sprintf always prints the entire number even if it's bigger than the field width, so this is never going to work for 10 bit binary.
In Section
Seekers of Perl Wisdom
|
|