Convert HEX to string in PHP | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 114

Convert HEX to string in PHP

Hi, friends. I need help PHP. How a variable type HEX var=0x31002300330006; to convert to string var_str='31002300330006';

21st Oct 2017, 2:28 PM
Skail
Skail - avatar
5 Answers
+ 8
$hexNum = 0x64; $str = dechex($hexNum); (Edited)
21st Oct 2017, 7:05 PM
$machitgarha
$machitgarha - avatar
+ 57
But what if the MS SQL database is a large field, not a number, for example "binary(100)" 0x746D696E3D30303A30303A333000746D696E3D30303A30303A333000
27th Dec 2017, 6:54 AM
Skail
Skail - avatar
+ 5
Then PHP cannot hold it as an accurate number, so calculation will be hard. Maybe you should not save that long number, or you can write your own algorithm. Another suggestion, is to save that long number as a string, and then make operations on it. But I think in a 64bit OS, you can only save a number as integer up to 2**64 - 1, not just about PHP. EDIT: However, there are extensions or libraries that can handle bigger numbers.
27th Dec 2017, 7:05 AM
$machitgarha
$machitgarha - avatar
+ 5
можно средствами Ms Sql - declare @hexstring varchar(max); set @hexstring = '0xabcedf012439'; select CONVERT(varbinary(max), @hexstring, 1);
24th May 2019, 12:37 AM
Michail Getmanskiy
Michail Getmanskiy - avatar
+ 4
I've edited my answer. This would be the true answer!
27th Dec 2017, 6:46 AM
$machitgarha
$machitgarha - avatar