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 :-