How does unpack receive the unsignedlonglong type?

Source: Internet
Author: User
How does an unpack receive unsignedlonglong type server in the small-end mode and the first eight bytes are unsigned long data? how can I use unpack to read it?
Unpack ("Q8md5/a10end_str", $ recv_body); no thanks


Reply to discussion (solution)

Split two 32-bit unpacks. it is an integer, not a floating point.
Directly return the results and check whether the system will overflow.

What you wrote above does not conform to the unpack syntax.

Ah, how can I write it? can you help me write it? thank you!

Code Description
A NUL-padded string
A space-padded string
H Hex string, low nibble first
H Hex string, high nibble first
C signed char
C unsigned char
S signed short (always 16 bit, machine byte order)
S unsigned short (always 16 bit, machine byte order)
N unsigned short (always 16 bit, big endian byte order)
V unsigned short (always 16 bit, little endian byte order)
I signed integer (machine dependent size and byte order)
I unsigned integer (machine dependent size and byte order)
L signed long (always 32 bit, machine byte order)
L unsigned long (always 32 bit, machine byte order)
N unsigned long (always 32 bit, big endian byte order)
V unsigned long (always 32 bit, little endian byte order)
F float (machine dependent size and representation)
D double (machine dependent size and representation)
X NUL byte
X Back up one byte
@ NUL-fill to absolute position

No Q

So how can I write it? can you change it for me? Thank you.

Let me guess what you want
Unpack ("Q8md5/a10end_str", $ recv_body)
Ying writing
Unpack ("Qmd5/a10end_str", $ recv_body)
Although 32-bit php does not support 64-bit integers, the rules are still required.
Q8 indicates 8 64-bit integers.

Since it is named md5, it can also be viewed as an integer.
$ A = unpack ("amd5/a10end_str", $ recv_body );
$ A ['md5'] isn't it the result you want?

No, amd5 only solves the first byte...

This md5 is written by myself. it is actually an unsigned long value. how can this type of value be solved?

You 'd better paste the base64_encode ($ recv_body) result
We can discuss it with the sample data.

?????? ALLDATAEND
The first eight bytes are eight digits followed by the text ALLDATAEND;
Unpack ("Nn1/a10end_str", $ recv_body );
Using this solution, n1 is a negative number-1935870548
It should be 441051427183631500 correct.

You
Echo base64_encode ($ recv_body );
Post result

Only with raw data can I tell you exactly how to write

Recv_body is ===> jJz1rO/tHgZBTExEQVRBRU5E
This is the trouble.

$s = base64_decode('jJz1rO/tHgZBTExEQVRBRU5E');$t = unpack('a8n/a10end_str', $s);$t['n'] = rmul($t['n']);print_r($t);function rmul($w) {  $n = 0;  foreach(array_reverse(unpack('v4', $w)) as $v) $n = bcadd(bcmul($n, 65536), $v);  return $n;}
Array
(
[N] = & gt; 441051427183631500
[End_str] => ALLDATAEND
)

Thank you very much for the complexity. isn't unpack capable of decoding such a long number?

Php is compiled by a 32-bit compiler, so it cannot process 64-bit integers.
If you compile with a 64-bit compiler, you can support 64-bit integers.
Of course, the Q and q modes can also be used, which is simple.

Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.