a = 300;
while (a) {
 b = a % 16;
 a /= 16;
 *buf-- = b + b>9?('a'-10):'0';
}