boost::format is slow to compile, slow to run, and has an unpleasant interface.
See https://svn.boost.org/trac/boost/ticket/9360 It seems that the %X specifier is ignored if the input value is a char type and the char is instead output verbatim and not in its integer value. Casting it to an int works around this.