Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • D

Idiom #142 Hexadecimal digits of an integer

Assign to string s the hexadecimal representation (base 16) of integer x.

E.g. 999 -> "3e7"

import std.conv;
s = to!string(x, 16);

std.conv.to is the entry point for any standard convertion.
import std.format;
s = format("%x", x);
char s[32];
snprintf(s, sizeof(s), "%x", i);

New implementation...