Created
January 29, 2015 02:34
-
-
Save waldemarnt/d04e65a51a9cc3e56063 to your computer and use it in GitHub Desktop.
This is a simple way to convert the 32bits account ids in a 64bits and 64bits in a 32bits id usgin php gmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define("STEAM_ID_UPPER_32_BITS", "00000001000100000000000000000001"); | |
// gets the lower 32-bits of a 64-bit steam id | |
function GET_32_BIT ($ID_64) { | |
$upper = gmp_mul( bindec(STEAM_ID_UPPER_32_BITS) , "4294967296" ); | |
return gmp_strval(gmp_sub($ID_64,$upper)); | |
} | |
// creates a 64-bit steam id from the lower 32-bits | |
function MAKE_64_BIT ( $ID_32 = 95374551, $hi = false ) { | |
if ($hi === false) { | |
$hi = bindec(STEAM_ID_UPPER_32_BITS); | |
} | |
// workaround signed/unsigned braindamage on x32 | |
$hi = sprintf ( "%u", $hi ); | |
$ID_32 = sprintf ( "%u", $ID_32 ); | |
return gmp_strval ( gmp_add ( gmp_mul ( $hi, "4294967296" ), $ID_32 ) ); | |
} | |
var_dump(MAKE_64_BIT()); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment