Voting

: max(zero, zero)?
(Example: nine)

The Note You're Voting On

mahdiyari
2 years ago
Zero padded hex strings as a pair of 2 (8bit).

<?php
function dec2hex($int) {
$hex = dechex($int);
if (
strlen($hex)%2 != 0) {
$hex = str_pad($hex, strlen($hex) + 1, '0', STR_PAD_LEFT);
}
return
$hex;
}

dec2hex(2); // 02
dec2hex(10); // 0a
dec2hex(256); // 0100
?>

<< Back to user notes page

To Top