Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

php - Convert from 64bit number to 32bit number

Trying a lot and just failing..

$x = 76561198005785475;

I want to this number, turn into this:

$y = 45519747;

That is the 32bit form of it.


Trying to explain with more details:

http://www.tonymarston.net/php-mysql/converter.php

1) Put the value 76561198005785475 on the "Decimal (input)" field. 2) Press "DEC to BIN" on the "Binary (Base 2)" field. 3) Count 32 starting from the RIGHT and copy it. 4) Paste the 32 chars binary number on "Binary (Base 2)" field. 5) Press "Bin to Dec" button on the "Binary (Base 2)" field.

Ok, now you can see the "45519747" number.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

$y = $x & 0xffffffff;

This will truncate your 64-bit value to a 32-bit value, but note that there is absolutely no way to get the 64-bit value back, this is a destructive method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...