dechex

(PHP 4, PHP 5, PHP 7)

dechexПереводит число из десятичной системы счисления в шестнадцатеричную

Описание

string dechex ( int $number )

Возвращает строку, содержащую шестнадцатеричное представление указанного безнакового аргумента number.

Наибольшее число, которое может быть преобразовано - PHP_INT_MAX * 2 + 1 (или -1): на 32-битных платформах это 4294967295 в десятеричной системе, что конвертируется функцией dechex() в ffffffff.

Список параметров

number

Десятичное значение для преобразования

Так как тип PHP integer является знаковым, а dechex() работает с безнаковыми целыми, то отрицательные целые воспринимаются как безнаковые.

Возвращаемые значения

Шестнадцатеричное строковое представление number.

Примеры

Пример #1 Пример использования dechex()

<?php
echo dechex(10) . "\n";
echo 
dechex(47);
?>

Результат выполнения данного примера:

a
2f

Пример #2 Пример использования dechex() с большими целыми

<?php
// Вывод подразуемвает 32-битную платформу.
// Обратите внимание, что вывод одинаков для всех этих значений.
echo dechex(-1)."\n";
echo 
dechex(PHP_INT_MAX 1)."\n";
echo 
dechex(pow(232) - 1)."\n";
?>

Результат выполнения данного примера:

ffffffff
ffffffff
ffffffff

Смотрите также

  • hexdec() - Переводит число из шестнадцатеричной системы счисления в десятичную
  • decbin() - Переводит число из десятичной системы счисления в двоичную
  • decoct() - Переводит число из десятичной системы счисления в восьмеричную
  • base_convert() - Преобразование числа между произвольными системами счисления

Коментарии

Heres a example of dec to html hex gradient. Have fun :)

//Amount of gradients
$l = 20;

//Start color
$start[0] = "255";     //red
$start[1] = "0";     //green
$start[2] = "255";     //blue

//End color
$end[0] = "255";     //red
$end[1] = "255";    //green
$end[2] = "255";    //blue

for ($t = 1; $t < $l;) {

    $x = $x * $t;

    for ($i = 0; $i < 3;) {

        $buffer[$i] = $start[$i] - $end[$i];
        $buffer[$i] = floor($buffer[$i] / $l);
        $rgb[$i] = $start[$i] - ($buffer[$i] * $t);

        if ($rgb[$i] > 255) {

            $rgb[$i] = 255;

        }

        $rgb[$i] = dechex($rgb[$i]);
        $rgb[$i] = strtoupper($rgb[$i]);

        if (strlen($rgb[$i]) < 2) {

            $rgb[$i] = "0$rgb[$i]";

        }

        $i++;

    }

    $color = "$rgb[0]$rgb[1]$rgb[2]";
    echo "$color";
        $t++;

}

?>
2002-02-11 07:39:03
http://php5.kiev.ua/manual/ru/function.dechex.html
Here's a function which works for decimal values up to 9007199254740992 (hex 20000000000000).

function dec2hex($dec)
{
  $hex = ($dec == 0 ? '0' : '');

  while ($dec > 0)
  {
    $hex = dechex($dec - floor($dec / 16) * 16) . $hex;
    $dec = floor($dec / 16);
  }

  return $hex;
}
2002-02-12 17:47:11
http://php5.kiev.ua/manual/ru/function.dechex.html
Here are two functions that will convert large dec numbers to hex and vice versa. And I really mean LARGE, much larger than any function posted earlier.

<pre>
// Input: A decimal number as a String.
// Output: The equivalent hexadecimal number as a String.
function dec2hex($number)
{
    $hexvalues = array('0','1','2','3','4','5','6','7',
               '8','9','A','B','C','D','E','F');
    $hexval = '';
     while($number != '0')
     {
        $hexval = $hexvalues[bcmod($number,'16')].$hexval;
        $number = bcdiv($number,'16',0);
    }
    return $hexval;
}

// Input: A hexadecimal number as a String.
// Output: The equivalent decimal number as a String.
function hex2dec($number)
{
    $decvalues = array('0' => '0', '1' => '1', '2' => '2',
               '3' => '3', '4' => '4', '5' => '5',
               '6' => '6', '7' => '7', '8' => '8',
               '9' => '9', 'A' => '10', 'B' => '11',
               'C' => '12', 'D' => '13', 'E' => '14',
               'F' => '15');
    $decval = '0';
    $number = strrev($number);
    for($i = 0; $i < strlen($number); $i++)
    {
        $decval = bcadd(bcmul(bcpow('16',$i,0),$decvalues[$number{$i}]), $decval);
    }
    return $decval;
}
</pre>
2002-04-28 12:21:06
http://php5.kiev.ua/manual/ru/function.dechex.html
Here's how to use bitwise operations for RGB2hex conversion. This function returns hexadesimal rgb value just like one submitted by gurke@bigfoot.com above.

function hexColor($color) {
  return dechex(($color[0]<<16)|($color[1]<<8)|$color[2]);
}

example:

$col[0] = 25;
$col[1] = 255;
$col[2] = 55;

print hexColor($col);
2002-09-23 22:20:38
http://php5.kiev.ua/manual/ru/function.dechex.html
now, here is a nice and small function to convert integers to hex strings and it avoids use of the DECHEX funtion because that function changed it's behavior too often in the past (now, in PHP version 4.3.2 it works with numbers bigger than 0x7FFFFFFF correctly, but i need to be backward compatible).

function &formatIntegerForOutput($value) {
    $text = "00000000";
    $transString = "0123456789ABCDEF";
    // handle highest nibble (nibble 7):
        $nibble = $value & 0x70000000;
        $nibble >>= 28;
        if ($value < 0) {
            $nibble = $nibble | 0x00000008;
        }
        $text[0] = $transString[$nibble];
        $value &= 0x0FFFFFFF;
    // nibbles 0 to 6:
        for ($a = 7; $a > 0; $a --) {
            $nibble = $value & 0x0000000F;
            $text[$a] = $transString[$nibble];
            $value >>= 4;
        }
    return $text
}

this function should be not too slow and is really simple.
I don't know, if the DECHEX function in the future will pad it's output to ever be 8 characters in length - so for backward compatibility reasons even in future PHP versions i avoided to use it.
2003-07-19 13:53:32
http://php5.kiev.ua/manual/ru/function.dechex.html
Автор:
Create Random Hex Color:

function make_seed() { 
   list($usec, $sec) = explode(' ', microtime()); 
   return (float) $sec + ((double) $usec * 100000); 


function rand_hex() {
   mt_srand(make_seed()); 
   $randval = mt_rand(0,255);
   //convert to hex
   return sprintf("%02X",$randval);
}

function random_color(){
   return "#".rand_hex().rand_hex().rand_hex();
}

hme ;)
2003-09-16 18:36:00
http://php5.kiev.ua/manual/ru/function.dechex.html
Easiest :P way to create random hex color:

<?php
function rand_color() {
    return 
substr('00000' dechex(mt_rand(00xffffff)), -6);
}
?>
2004-02-05 11:05:38
http://php5.kiev.ua/manual/ru/function.dechex.html
/*
* RGB-Colorcodes(i.e: 255 0 255) to HEX-Colorcodes (i.e: FF00FF)
*/
function rgb2hex($rgb){
    if(!is_array($rgb) || count($rgb) != 3){
        echo "Argument must be an array with 3 integer elements";
        return false;
    }
    for($i=0;$i<count($rgb);$i++){
        if(strlen($hex[$i] = dechex($rgb[$i])) == 1){
            $hex[$i] = "0".$hex[$i];
        }
    }
    return $hex;
}
/* Example */
print_r(rgb2hex(array(10,255,255)));
2004-02-09 18:39:07
http://php5.kiev.ua/manual/ru/function.dechex.html
Here's my version of a red->yellow->green gradient:

<?php
function colorMeter($percent$invert false)
{
   
//$percent is in the range 0.0 <= percent <= 1.0
    //    integers are assumed to be 0% - 100%
             // and are converted to a float 0.0 - 1.0
    //     0.0 = red, 0.5 = yellow, 1.0 = green
    //$invert will make the color scale reversed
    //     0.0 = green, 0.5 = yellow, 1.0 = red 
   
    //convert (int)% values to (float)
   
if (is_int($percent)) $percent $percent 0.01;
   
   
$R min((2.0 * (1.0-$percent)), 1.0) * 255.0;
   
$G min((2.0 $percent), 1.0) * 255.0;
   
$B 0.0;
   
    return ((
$invert) ? 
sprintf("%02X%02X%02X",$G,$R,$B
sprintf("%02X%02X%02X",$R,$G,$B)); 
//colorMeter
?>

and use it like this:

<TABLE BORDER=1 WIDTH="300">
<?php
for ($i 0.0$i <= 1.0$i += 0.10)
{
   
$RGB colorMeter($i);
    print 
"<TR><TD BGCOLOR='".$RGB."'>".$i."</TD><TD>
<PRE>"
.$RGB."</PRE></TD></TR>\n";
}
?>
</TABLE>

<P>

<TABLE BORDER=1 WIDTH="300">
<?php
for ($i 0$i <= 100$i += 10)
{
   
$RGB colorMeter(intval($i), true);
    print 
"<TR><TD BGCOLOR='".$RGB."'>".$i."</TD><TD>
<PRE>"
.$RGB."</PRE></TD></TR>\n";
}
?>
</TABLE>
2004-03-18 16:59:51
http://php5.kiev.ua/manual/ru/function.dechex.html
<?php
/*
here are two functions, some might find them useful (maybe for encoding) 
converting string to hex and hex to string:
*/

function strhex($string)
{
   
$hex="";
    for (
$i=0;$i<strlen($string);$i++)
       
$hex.=(strlen(dechex(ord($string[$i])))<2)? "0".dechex(ord($string[$i])): dechex(ord($string[$i]));
    return 
$hex;
}
function 
hexstr($hex)
{
   
$string="";
    for (
$i=0;$i<strlen($hex)-1;$i+=2)
       
$string.=chr(hexdec($hex[$i].$hex[$i+1]));
    return 
$string;
}
?>
2004-04-21 15:01:18
http://php5.kiev.ua/manual/ru/function.dechex.html
Автор:
If you need to convert RGB-color into HEX-color, use this:
<?php
function rgb2hex($rgb){
    return 
sprintf("%06X"$rgb);
}
$hex rgb2hex(65280); // 00FF00
?>
2004-12-11 15:30:17
http://php5.kiev.ua/manual/ru/function.dechex.html
Автор:
If you need to generate random HEX-color, use this:
<?php
function random_hex_color(){
    return 
sprintf("%02X%02X%02X"mt_rand(0255), mt_rand(0255), mt_rand(0255));
}
$hex random_hex_color(); // 09B826
?>

Enjoy.
2004-12-12 09:31:31
http://php5.kiev.ua/manual/ru/function.dechex.html
This function will take a string and convert it into a hexdump.

e.g.

3c666f6e 74207369 7a653d22 33223e4c  <font.size."3">L
6561726e 20686f77 20746f20 62652061  earn.how.to.be.a

function hexdump($string) {
   $hex="";
   $substr = "";
   for ($i=0; $i < strlen($string) ;$i++) {
     if(!($i % 4) && $i != 0) {
       $hex .= " ";
     }
     if(!($i % 16) && $i != 0) {
       $clean = preg_replace("/[^a-zA-Z0-9!-.<>\/]/",".",$substr);
       $hex .= " ".htmlentities($clean)."\n";
       $substr = "";
     }
     $substr .=  $string[$i];
     $hex .= dechex(ord($string[$i]));
   }
   return $hex;
}
2004-12-15 01:36:00
http://php5.kiev.ua/manual/ru/function.dechex.html
I see a lot of less-than-optimal functions posted on this page, so I feel I have to give some better examples... 
due to the sheer size of this collection, I have made it available on my server, rather than copy/paste it into these comments.

http://ryo-ohki.4th-age.com/demos/able.php
and
http://ryo-ohki.4th-age.com/demos/able.phps

dechex replacement function from above source:
<?php
  define
('BIT_BYTE'8); // bits per byte
 
define('HEX_BYTE'BIT_BYTE/4); // hex digits in a byte

 
define('BIT_INT'32); // sizeof(int)
 
define('HEX_INT'BIT_INT / (BIT_BYTE/HEX_BYTE)); // hex digits in an int

 
function i2h($int$group=HEX_BYTE$size=HEX_INT$sep=' ') {
   
$ret '';
    while(
$size--) {
     
$n=($int>>($size*4)) & 0xf;
     
$ret .= $n>9?chr(55 $n):$n;
      if(
$size && $size%$group == 0$ret .= $sep;
    }
    return 
$ret;
  }

  echo 
i2h(rand(1,2)==1?-mt_rand():mt_rand());
?>
2005-01-02 06:30:46
http://php5.kiev.ua/manual/ru/function.dechex.html
Here is a very small zeropadding that you can use for numbers:

function zeropad($num, $lim)
{
   return (strlen($num) >= $lim) ? $num : zeropad("0" . $num);
}

zeropad("234",6);

will produce:
000234

zeropad("234",1);

will produce:
234
2005-05-01 22:28:19
http://php5.kiev.ua/manual/ru/function.dechex.html
A less elegant but (perhaps) faster way to pad is with substr with a negative length argument. I use it in this tiny function which formats computed rgb color codes for style sheets:
<?
function toColor($n)
{
return(
"#".substr("000000".dechex($n),-6));
}
?>
2005-05-28 22:33:06
http://php5.kiev.ua/manual/ru/function.dechex.html
Warning for use on 64 bit machines! The Extra length matters!

32bit machine:
php -r 'echo dechex(4294967295);'
output: ffffffff

64bit machine:
php -r 'echo dechex(4294967295);'
output: ffffffff

so far it is ok. But for slightly bigger numbers:

32bit machine:
php -r 'echo dechex(4294967296);'
output: 0

64bit machine:
php -r 'echo dechex(4294967296);'
output: 100000000

note the difference!

This is particularly important when converting negative numbers:

64bit machine:
php -r 'echo dechex(-1);'
output: ffffffffffffffff

32bit machine:
php -r 'echo dechex(-1);'
output: ffffffff

If you want your code to be portable to amd64 or xeons (which are now quite popular with hosting companies) then you must ensure that your code copes with the different length of the result for negative numbers (and the max value, although that is probably less critical).
2005-06-14 04:46:24
http://php5.kiev.ua/manual/ru/function.dechex.html
A handy little function to convert HEX colour codes to "web safe" colours...

<?php

function color_mkwebsafe $in )
{
   
// put values into an easy-to-use array
   
$vals['r'] = hexdecsubstr($in02) );
   
$vals['g'] = hexdecsubstr($in22) );
   
$vals['b'] = hexdecsubstr($in42) );

   
// loop through
   
foreach( $vals as $val )
    {
       
// convert value
       
$val = ( round($val/51) * 51 );
       
// convert to HEX
       
$out .= str_pad(dechex($val), 2'0'STR_PAD_LEFT);
    }

    return 
$out;
}

?>

Example: color_mkwebsafe('0e5c94');
Produces: 006699

Hope this helps someone out... Happy coding. :-)
2005-10-27 19:45:08
http://php5.kiev.ua/manual/ru/function.dechex.html
These are functions to convert roman numbers (e.g. MXC) into dec and vice versa.
Note: romdec() does not check whether a string is really roman or not. To force a user-input into a real roman number use decrom(romdec($input)). This will turn XXXX into XL for example.

<?php
   
function decrom($dec){
       
$digits=array(
           
=> "I",
           
=> "IV",
           
=> "V",
           
=> "IX",
           
10 => "X",
           
40 => "XL",
           
50 => "L",
           
90 => "XC",
           
100 => "C",
           
400 => "CD",
           
500 => "D",
           
900 => "CM",
           
1000 => "M"
       
);
       
krsort($digits);
       
$retval="";
        foreach(
$digits as $key => $value){
            while(
$dec>=$key){
               
$dec-=$key;
               
$retval.=$value;
            }
        }
        return 
$retval;
    }

    function 
romdec($rom){
       
$digits=array(
           
"I" => 1,
           
"V" => 5,
           
"X" => 10,
           
"L" => 50,
           
"C" => 100,
           
"D" => 500,
           
"M" => 1000
       
);
       
$retval="";
       
$chars=array();
        for(
$i=1;$i<=strlen($rom);$i++){
           
$chars[]=substr($rom,$i-1,1);
        }
       
$step=1;
        for(
$i=count($chars)-1;$i>=0;$i--){
            if(!isset(
$digits[$chars[$i]])){ return "Error!"; }
            if(
$step<=$digits[$chars[$i]]){
               
$step=$digits[$chars[$i]];
               
$retval+=$digits[$chars[$i]];
            }
            else{
               
$retval-=$digits[$chars[$i]];
            }
        }
        return 
$retval;
    }

    echo 
decrom(romdec("XXXX"));
?>
2005-12-28 07:00:10
http://php5.kiev.ua/manual/ru/function.dechex.html
Автор:
Be very careful calling dechex on a number if it's stored in a string.

For instance:

The max number it can handle is 4294967295 which in hex is FFFFFFFF, as it says in the documentation.

dechex(4294967295) => FFFFFFFF //CORRECT

BUT, if you call it on a string of a number, it casts to int, and automatically gives you the largest int it can handle.

dechex('4294967295') => 7FFFFFFF //WRONG!

so you'll need to cast to a float:

dechex((float) '4294967295') => FFFFFFFF //CORRECT

This took me FOREVER to figure out, so hopefully I just saved someone some time.
2006-12-16 01:33:16
http://php5.kiev.ua/manual/ru/function.dechex.html
To force the correct usage of 32-bit unsigned integer in some functions, just add '+0'  just before processing them.

for example 
<?php echo(dechex("2724838310")); ?>
will print '7FFFFFFF'
but it should print 'A269BBA6'

When adding '+0' php will handle the 32bit unsigned integer
correctly
<?php echo(dechex("2724838310"+0)); ?>
will print 'A269BBA6'
2007-03-09 09:28:19
http://php5.kiev.ua/manual/ru/function.dechex.html
I was challenged by a problem with large number calculations and conversion to hex within php. The calculation exceeded unsigned integer and even float range. You can easily change it for your needs but it is, thanks to bcmath, capable of handling big numbers via string. This function will convert them to hex.

In this specific example though, since I use it for game internals that can only handle 32 bit numbers, it will truncate calculations at 8 digits. If the input is 1 for example it will be filled up with zeros. Output 00000001h.

Of course I don't claim it to be a good one, but it works for me and my purpose. Suggestions on faster code welcome!

<?php
// Turns numbers into 32-bit hex string; Fills up zeros
function lrgDec2Hex($number)
{
   
$i 0;
   
$hex = array();

    while(
$i 8) {
        if(
$number == 0) {
           
array_push($hex'0');
        }
        else {
           
array_push($hexstrtoupper(dechex(bcmod($number'16'))));
           
$number bcdiv($number'16'0);
        }
       
$i++;
    }
   
krsort($hex);
    return 
implode($hex);
}
?>
2008-05-11 12:55:55
http://php5.kiev.ua/manual/ru/function.dechex.html
I was confused by dechex's size limitation. Here is my solution to the problem. It supports much bigger values, as well as signs.

<?php
function dec_to_hex($dec)
{
   
$sign ""// suppress errors
   
if( $dec 0){ $sign "-"$dec abs($dec); }

   
$hex = Array( => 0=> 1=> 2=> 3=> 4=> 5,
                 
=> 6=> 7=> 8=> 910 => 'a',
                 
11 => 'b'12 => 'c'13 => 'd'14 => 'e',   
                 
15 => 'f' );
       
    do
    {
       
$h $hex[($dec%16)] . $h;
       
$dec /= 16;
    }
    while( 
$dec >= );
   
    return 
$sign $h;
}
?>
2008-10-29 04:23:59
http://php5.kiev.ua/manual/ru/function.dechex.html
for mac address
<?php
function dec2mac($mac) {
   
$mac=preg_split("([.])"$mac6);
   
$hexmac="";
   foreach (
$mac as $part
   {
   
$part=dechex($part);
   
strlen($part)<$hexmac.="0$part$hexmac.=$part;
   }
   return 
$hexmac;

echo 
dec2mac("0.29.96.71.60.137"); // 001d60473c89
?>
2011-11-02 00:11:09
http://php5.kiev.ua/manual/ru/function.dechex.html
If you need to convert a large number (> PHP_MAX_INT) to a hex value, simply use base_convert. For example:

base_convert('2190964402', 10, 16); // 829776b2
2012-03-07 16:44:11
http://php5.kiev.ua/manual/ru/function.dechex.html
If you want to create or parse signed Hex values:

<?php
// $d should be an int
function sdechex($d) { return ($d<0) ? ('-' dechex(-$d)) : dechex($d); }

// $h should be a string
function shexdec($h) { return ($h[0] === '-') ? -('0x' substr($h,1) + 0) : ('0x' $h 0); }

// test

$v sdechex(-123); // string(3) "-7b"
$i shexdec($v);   // int(-123)
var_dump($v$i);
?>

Also note that ('0x' . $str + 0) is faster than hexdec()
2012-03-23 09:09:50
http://php5.kiev.ua/manual/ru/function.dechex.html
I wrote this to convert hex into signed int, hope this helps someone out there... peace :)

<?php
$hex 
dechex(-32767);
$dec shexdex($hex);

function 
shexdex($hex){
   
$dec hexdec($hex);
   
   
// Negative number (in binary if the msb is 1 then it is neg)
    // since one hex is 4bits, the value 8 and up contain msb of 1, hence negative number   
   
if ($hex[0] >= '8'){    // Note: if you use the digit 8 it is not the same as '8'
       
$dec -= 1;
       
$dec = ~$dec;
       
        return -
$dec;
    }
   
    return 
$dec;
}

if (
$dec == -32767){
    echo 
'Yay!';
}
?>
2012-10-03 04:02:34
http://php5.kiev.ua/manual/ru/function.dechex.html
Javascript Crypt:

<?php
function jsCrypt($script,$level=1){
    for (
$j=0;$j<$level;$j++){
       
$asc='';
        for (
$i=0;$i<strlen($script);$i++)
           
$asc.='%'.dechex(ord($script[$i]));
       
$script='<SCRIPT LANGUAGE="JavaScript">document.write(unescape(\''.$asc.'\'));</SCRIPT>';
    }
    return 
$script;
}

echo 
jsCrypt('<script>alert(123);</script>',1);
?>
2012-12-13 16:26:31
http://php5.kiev.ua/manual/ru/function.dechex.html
Автор:
Or you could use this for an RGBA color.
    function toAlphaColor($n,$a)
    {
        $rgb = substr("000000".dechex($n),-6);
        $alpha = substr("00".dechex($a),-2);
        return("#".$rgb.$alpha);
    }
2013-11-10 17:56:25
http://php5.kiev.ua/manual/ru/function.dechex.html
I figured out another way to do this:
if you have a very long decimal number in gmp format (you can always create a gmp number with gmp_init($numberstring), you can simply do gmp_strval($gmpnumber, 16), where $gmpnumber is your gmp number, and the 16 is the base you want to transform it to. Worked for me like a charm, also works for other bases.
2014-08-01 01:02:21
http://php5.kiev.ua/manual/ru/function.dechex.html
this base function convert string rgb to color
<?php
   
function rgb_to_color($rgb$symbols=' '){
       
$color '';
       
$arr explode($symbols$rgb);
       
$count count($arr);
        for(
$i=0$i<$count$i++){
           
$color .= dechex($arr[$i]);
        }
        return 
'#'.$color;
    }
       echo 
rgb_to_color('186 186 18');  // #baba12
   
echo rgb_to_color('186-186-18''-');  // #baba12
?>
2014-09-02 00:16:55
http://php5.kiev.ua/manual/ru/function.dechex.html
I like the example with the bitwise operations but if the value of color[0] is less than 16 it's not accurate:
example:
color[0]: 0;
color[1]: 0;
color[2]: 255;
 function hexColor($color) {
  return dechex(($color[0]<<16)|($color[1]<<8)|$color[2]);
}
It returns "ff", which is not legit RGB color...
so my solution is to combine the function above with: 
function toColor($n)
{
return("#".substr("000000".dechex($n),-6));
}

If you gotta deal with array of rgb values this is my solution:
------------------------------------------------------
function hexColor($color) {
    $rgb = dechex(($color[0]<<16)|($color[1]<<8)|$color[2]);
    return("#".substr("000000".$rgb, -6));
}
------------------------------------------------------
2015-04-30 17:43:58
http://php5.kiev.ua/manual/ru/function.dechex.html
Автор:
warning jbleau dec_to_hex method is buggy, avoid it.

dec_to_hex('9900000397')-->24e16048f
dec_to_hex('9900000398')-->24e16048f
dec_to_hex('9900000399')-->24e16048f
2017-04-24 20:12:05
http://php5.kiev.ua/manual/ru/function.dechex.html
Автор:
Zero padded hex strings as a pair of 2 (8bit).

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

dec2hex(2); // 02
dec2hex(10); // 0a
dec2hex(256); // 0100
?>
2022-07-24 14:45:11
http://php5.kiev.ua/manual/ru/function.dechex.html

    Поддержать сайт на родительском проекте КГБ