javascriptnode.jssteam

Convert 64 bit Steam ID to 32 bit account ID


How do I convert a 64 bit steam ID to a 32 bit account ID? Steam says to take the first 32 bits of the number, but how do you do this in Node?

Do I need to use BigNumber to store the 64 bit int?


Solution

  • Nodejs now supports BigInt as of Node version ~10. Additionally, MDN shows that BigInt is widely available in the browser.

    This allows for simple subtraction:

    // Note: Pass your number as a string to the BigInt constructor
    // Number to subtract from your 64-bit SteamID
    const steamBaseline = BigInt("76561197960265728");
    // Your 64-bit SteamID
    const steamId64 = BigInt("76561197991791363");
    // Result
    const steamId32 = (steamId64 - steamBaseline).toString();