Jump to content

[SOLVED] decimal to hex converting


bbunlock

Recommended Posts

I have a flex app that was made for me that sends the values via the post method, the problem is that the color values are sent in decimal format.

 

I have used the dec2hex function and it works on some of them but it fails on others, for example the post data might send "16763955" which I can convert using the dechex function into its correct hex color code example "00ff00" BUT some of the decimal values are for example "65535" which converts to "33cc" which is no good becuase the correct value is "0033cc" it apears that dechex will not convert these correctly.

 

is there another function that I have missed that will convert them to the correct hex code? I have sent the flex developer an email a couple of days ago but heard nothing back so diceded to try a php convert instead but having problems as described above.

 

if anyone can suggest another method to get the correct values then please reply to let me know

 

thanks in advance

 

wayne

Link to comment
https://forums.phpfreaks.com/topic/104913-solved-decimal-to-hex-converting/
Share on other sites

<?php
$dec = 65535;
$hex = sprintf('%d --> %06X', $dec, $dec);
echo $hex;                                   // 00FFFF

echo '<br>';

$dec = 13260;
$hex = sprintf('%d --> %06X', $dec, $dec);
echo $hex;                                   // 0033CC

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.