Logo

Programming-Idioms

  • Dart
  • Java

Idiom #142 Hexadecimal digits of an integer

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

E.g. 999 -> "3e7"

String s = "%x".formatted(x);
String s = Integer.toHexString(x);
import java.util.HexFormat;
String s = HexFormat.of().toHexDigits(x);
var s = x.toRadixString(16);
char s[32];
snprintf(s, sizeof(s), "%x", i);

New implementation...