Skip to content

Instantly share code, notes, and snippets.

@waldemarnt
Created January 29, 2015 02:34
Show Gist options
  • Save waldemarnt/d04e65a51a9cc3e56063 to your computer and use it in GitHub Desktop.
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
<?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