How can we convert a piece of data into a hex format,
This is the data in a blob. now I use stream_get_contents to extract the data and convert it directly into the right-side ascii format in the graph, but it is not based on ascii in the protocol. How can I retrieve or convert it into a hex string?
Reply to discussion (solution)
First, clarify one thing
The ASCII form on the right and HEX form in the middle of the figure are the same thing (we call it a binary string)
These two representation methods are not used for actual data communication, and binary strings are still used for communication.
$s = 'ABCDEFGHIJKLMNOP';echo strtoupper(join(' ', str_split(bin2hex($s), 4)));
4142 4344 4546 4748 494A 4B4C 4D4E 4F50
I feel that the function used for the value is incorrect, but I have little experience. What can be used to make the original data into strings?
First, clarify one thing
The ASCII form on the right and HEX form in the middle of the figure are the same thing (we call it a binary string)
These two representation methods are not used for actual data communication, and binary strings are still used for communication.
$s = 'ABCDEFGHIJKLMNOP';echo strtoupper(join(' ', str_split(bin2hex($s), 4)));
4142 4344 4546 4748 494A 4B4C 4D4E 4F50
Bamboo is big enough to come ~~~ I understand this now. in our protocol, we use a section of hex to parse data. for example, the second row of DD07 is converted to decimal followed by 221 and 7, later, the agreement stipulates that 221 + 7*256 = 2013. But now I have taken this character directly into the ascii format, and the protocol will not work. my problem is that, how can I get it out of the hex format?
First, clarify one thing
The ASCII form on the right and HEX form in the middle of the figure are the same thing (we call it a binary string)
These two representation methods are not used for actual data communication, and binary strings are still used for communication.
$s = 'ABCDEFGHIJKLMNOP';echo strtoupper(join(' ', str_split(bin2hex($s), 4)));
4142 4344 4546 4748 494A 4B4C 4D4E 4F50
Thank you! I have solved this problem.
HEX is used only for intuitive description.
If the hexadecimal format of a string is DD07
You can write in php.
$ S = chr (0xdd). chr (0x07 );
Echo ord ($ s {0}; /// 221
Echo ord ($ s {1}; // 7