BITMASK_SNPRINTF(9)    NetBSD Kernel Developer's Manual    BITMASK_SNPRINTF(9)

     bitmask_snprintf -- bitmask output conversion

     #include <sys/systm.h>

     char *
     bitmask_snprintf(u_quad_t val, const char *fmt, char *buf,
         size_t buflen);

     The bitmask_snprintf() function formats a bitmask into a mnemonic form
     suitable for printing.

     This conversion is useful for decoding bit fields in device registers.
     specified radix and an interpretation of the bits within that integer as
     though they were flags.

     The decoding directive string fmt describes how the bitfield is to be
     interpreted and displayed.  It follows two possible syntaxes, referred to
     as ``old'' and ``new''.  The main advantage of the ``new'' formatting is
     that it is capable of handling multi-bit fields.

     the format string follows the ``new'' syntax.  The second character (the

     The remaining characters in fmt are interpreted as a list of bit-posi-
     tion-description pairs.  From here the syntaxes diverge.

     The ``old'' format syntax is series of bit-position-description pairs.
     Each begins with a binary character value that represents the position of

     The remaining characters in a bit-position-description pair are the char-
     acters to print should the bit being described be set.  Description
     strings are delimited by the next bit position value character encoun-
     tered (distinguishable by its value being <= 32), or the end of the
     decoding directive string itself.

     For the ``new'' format syntax, a bit-position-description begins with a
     The least significant bit is bit-position zero, unlike the ``old'' syntax
     where it is one.

     b\B    Describes a bit position.  The bit-position B indicates the corre-
            sponding bit, as in the ``old'' format.

            the second character of the decoding directive string fmt.




     Finally, each field is delimited by a NUL (`\0') character.  By conven-
     tion, the format string has an additional NUL character at the end, fol-
     lowing that delimiting the last bit-position-description pair.

     The buffer buf passed to bitmask_snprintf must be at least
     KPRINTF_BUFSIZE bytes in length.  See the source code for the definition
     of this macro.

     The bitmask_snprintf() function returns the buffer buf.  The returned
     string is always NULL-terminated.

     Two examples of the old formatting style:

           bitmask_snprintf(3, "\10\2BITTWO\1BITONE", buf, buflen)
           => "3<BITTWO,BITONE>"

                   buf, buflen)

     An example of the new formatting style:

                   buf, buflen)
           => "800f0701<LSB,NIBBLE2=0,BURST=f=SIXTEEN,MSB>"

     bitmask_snprintf() will still return the buffer, containing a truncated



     The bitmask_snprintf() function was originally implemented as a non-stan-
     dard %b format string for the kernel printf() function in NetBSD 1.5 and
     earlier releases.

     The ``new'' format was the invention of Chris Torek.

NetBSD 5.0.1                     July 29, 2007                    NetBSD 5.0.1




©1994 Man-cgi 1.15, Panagiotis Christias <>
©1996-2015 Modified for NetBSD by Kimmo Suominen