/* Encodes a 16-bit number into hexadecimal, writing exactly 4 hex chars.  */
static int write_hex16(char *out, uint16_t val)
/* Encodes a 16-bit number into hexadecimal, writing exactly 4 hex chars.  */
static int write_hex16(char *out, uint16_t val)
{
	const char *hex = "0123456789ABCDEF";
	*out++ = hex[(val >> 12) & 0xF];
	*out++ = hex[(val >> 8)  & 0xF];
	*out++ = hex[(val >> 4)  & 0xF];
	*out++ = hex[ val        & 0xF];
	return 4;
}