Skip to main content



  • toTwosComplement(value: Numbers, nibbleWidth?: number): string

  • Converts a negative number into the two’s complement and return a hexstring of 64 nibbles.

    console.log(web3.utils.toTwosComplement(13, 32));
    > 0x0000000000000000000000000000000d

    console.log(web3.utils.toTwosComplement('-0x1', 32));
    > 0xffffffffffffffffffffffffffffffff

    console.log(web3.utils.toTwosComplement(BigInt('9007199254740992'), 32));
    > 0x00000000000000000020000000000000


    • value: Numbers

      The value to be converted.

    • nibbleWidth: number = 64

      The nibble width of the hex string (default is 64).

    Returns string

    The hex string of the two’s complement.