Dec to HEX conversion
Dec to HEX conversion
Waynef
Posts: 9Questions: 0Answers: 0
HI All
I am using a MySQLi data connection example ( http://datatables.net/development/server-side/php_mysqli ) to retrieve the required data, this is working great but the information in the Database is stored in a decimal format. I need to display this as a Hex value.
I there a method to do this? I have search and date's can be reformatted and numbers formatted to show thousands etc, but nothing for hex.
Any pointers would be appreciated.
Regards
Wayne
I am using a MySQLi data connection example ( http://datatables.net/development/server-side/php_mysqli ) to retrieve the required data, this is working great but the information in the Database is stored in a decimal format. I need to display this as a Hex value.
I there a method to do this? I have search and date's can be reformatted and numbers formatted to show thousands etc, but nothing for hex.
Any pointers would be appreciated.
Regards
Wayne
This discussion has been closed.
Replies
MySQL has a conv() function which converts numbers between different number bases, but I couldn't say whether MySQLi has it.
Cheers
Allan
I have now managed to modify the data in the JSON data when using a MYSQLI script.
[code]
while ( $aRow = $rResult->fetch_assoc() ) {
$row = array();
for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
if ( $aColumns[$i] == 'version' ) {
// Special output formatting for 'version' column
$row[] = ($aRow[ $aColumns[$i] ]=='0') ? '-' : $aRow[ $aColumns[$i] ];
} elseif ( $aColumns[$i] != ' ' ) {
// General output
$row[] = $aRow[ $aColumns[$i] ];
}
}
$row[1] = sprintf("%X",($row[1]));
$output['aaData'][] = $row;
}
echo json_encode( $output );
[/code]
I have been able to do this by adding this $row[1] = sprintf("%X",($row[1])); line, it basically modifies the data in the array for the second column in the table. In this case converting the Decimal value into a Hex value.
Thanks for assistance
Wayne