41 39 34 32
2+5=7 bytes removed thanks to PrzemysławP.
I am using the
FORMAT function function, for printing a number as binary with padding and separators, called with the magic number 8800979740570 (a.k.a. 8012345679A in base 16):
CL-USER> (format t"~,,,4:b"8800979740570)
I used to do the same with 123456789A, but as noted by PrzemysławP, the order does not matter and we can save some bytes. This is because with the original order, the leading zeros would be done as padding and would not be separated into groups of 4 digits; here, by starting with 1000, we don't need any padding. In addition to that, I also removed the mincol argument (53) because I don't need to specify the size of the number anymore.
Formatted output of integers
The documentation for format (see above) is detailed for
~D (decimal base) but the same applies to other ones (hex
~R). Note that for floats there are other arguments.
The most general format is
~mincol,padchar,commachar,commaintervalD, but note that the two last arguments, commachar and commainterval are only meaningful if
D has a colon-modifier
:D, which by default separate digits by groups of 3 (commainterval is a custom value, instead of 3), inserting the commachar character between such groups, by default a comma.
The mincol argument is one that is found in other format directives and specifies the horizontal space allocated for the thing being printed. When the actual size required is smaller, a padding might be applied (left or right, or both for some directives). The padding fills the remaining space with padchar, a character. When the actual size is bigger, the layout might not be pretty but the object is printed fully.
More precisely (from the above link):
~D Decimal. An arg, which should be an integer, is printed in decimal
~D will never put a decimal point after the number.
uses a column width of mincol; spaces are inserted on the left if the
number requires fewer than mincol columns for its digits and sign. If
the number doesn't fit in mincol columns, additional columns are used
~mincol,padcharD uses padchar as the pad character instead of space.
The @ modifier causes the number's sign to be printed always; the
default is to print it only if the number is negative.
The : modifier
causes commas to be printed between groups of three digits
prefix parameter may be used to change the character used as the
comma. Thus the most general form of ~D is ~mincol,padchar,commacharD.
X3J13 voted in March 1988 (FORMAT-COMMA-INTERVAL) to
add a fourth parameter, the commainterval. This must be an integer; if
it is not provided, it defaults to 3. This parameter controls the
number of digits in each group separated by the commachar.
By extension, each of the ~B, ~O, and ~X directives accepts a
commainterval as a fourth parameter, and the ~R directive accepts a
commainterval as its fifth parameter.
Padding and separators
Note that the padding characters are not grouped, as explained above. For example, the zeros in front of the numbers are not separated:
CL-USER> (format t "~10,'0:d" 12345)
... there is no easy way to combine format parameters to output:
... that's why I first added the zeros and a comma explicitly in the answer. This is not necessary anymore.