dechex
dechex(int $number): string
Converts a decimal number to its hexadecimal string representation.
C C23
#include <stdio.h>
int main(void) {
printf("%x\n%x\n%x\n", 255, 2026, 4095);
return 0;
}
ff 7ea fff
C++ C++26
#include <iostream>
int main() {
std::cout << std::hex << 255 << "\n" << 2026 << "\n" << 4095 << "\n";
return 0;
}
ff 7ea fff
C# v11.0.100
Console.WriteLine(255.ToString("x"));
Console.WriteLine(2026.ToString("x"));
Console.WriteLine(4095.ToString("x"));
ff 7ea fff
Go v1.27.4
package main
import "fmt"
func main() {
fmt.Printf("%x\n%x\n%x\n", 255, 2026, 4095)
}
ff 7ea fff
Java v27.0.1
public class Main {
public static void main(String[] args) {
System.out.println(Integer.toHexString(255));
System.out.println(Integer.toHexString(2026));
System.out.println(Integer.toHexString(4095));
}
}
ff 7ea fff
JavaScript v26.13.1
console.log((255).toString(16));
console.log((2026).toString(16));
console.log((4095).toString(16));
ff 7ea fff
PHP v8.6.0
echo dechex(255), "\n", dechex(2026), "\n", dechex(4095);
ff 7ea fff
Python v3.15.2
print(format(255, "x"))
print(format(2026, "x"))
print(format(4095, "x"))
ff 7ea fff
Rust v1.99.1
fn main() {
println!("{:x}\n{:x}\n{:x}", 255, 2026, 4095);
}
ff 7ea fff
TypeScript v26.13.1
const n: number = 255;
console.log(n.toString(16));
console.log((2026).toString(16));
console.log((4095).toString(16));
ff 7ea fff
Language differences
C: %x; negatives expand as the bit pattern.
C++: std::hex; negatives expand as the bit pattern.
C#: the "x" format; negatives as 32-bit two's complement.
Go: %x; negatives print with a leading -; uppercase, the 0x prefix, and zero padding are formatting options (%X, %08x, likewise in the C family).
Java: Integer.toHexString; negatives always unsigned 32-bit.
JavaScript: (255).toString(16); negatives print a leading - (use >>> 0 to convert to unsigned 32-bit first for the two's-complement form).
PHP: decimal integer → hex string, and all examples agree — lowercase, no 0x prefix, no zero padding — via dechex; negatives expand as the bit pattern (64-bit on 64-bit platforms, so dechex(-1) is sixteen fs).
Python: format(n, 'x'); negatives print with a signed - prefix.
Rust: {:x}; negatives expand as the bit pattern.
TypeScript: same as JavaScript — (255).toString(16).