Bonsaiswap Docs
  • 🌿Bonsaiswap Intro
  • Get Started
    • Create a Wallet
    • Get ERC20 Tokens
  • Roadmap
  • Products
    • 🔄Exchange
      • Swapping Tokens
      • Providing Liquidity
    • 🔮Coming Soon!
  • Tokenomics
    • 🎍AKADAMA
  • Developers
    • 🛠️Technical Reference
      • Core
        • BonsaiswapV3Factory
        • BonsaiswapV3Pool
        • BonsaiswapV3PoolDeployer
        • Interfaces
          • IERC20Minimal
          • IBonsaiswapV3Factory
          • IBonsaiswapV3Pool
          • IBonsaiswapV3PoolDeployer
          • callback
            • IBonsaiswapV3FlashCallback
            • IBonsaiswapV3MintCallback
            • IBonsaiswapV3SwapCallback
          • Pool
            • IBonsaiswapV3PoolActions
            • IBonsaiswapV3PoolDerivedState
            • IBonsaiswapV3PoolEvents
            • IBonsaiswapV3PoolImmutables
            • IBonsaiswapV3PoolOwnerActions
            • IBonsaiswapV3PoolState
        • Libraries
          • BitMath
          • FixedPoint128
          • FixedPoint96
          • FullMath
          • LiquidityMath
          • LowGasSafeMath
          • Oracle
          • Position
          • SafeCast
          • SecondsOutside
          • SqrtPriceMath
          • SwapMath
          • Tick
          • TickBitmap
          • TickMath
          • TransferHelper
          • UnsafeMath
      • Periphery
        • Base
          • BlockTimestamp
          • ERC721Permit
          • LiquidityManagement
          • Multicall
          • PeripheryImmutableState
          • PeripheryPayments
          • PeripheryPaymentsWithFee
          • PoolInitializer
          • SelfPermit
        • Interfaces
          • IERC20Metadata
          • IERC721Permit
          • IMulticall
          • INonfungiblePositionManager
          • INonfungibleTokenPositionDescriptor
          • IPeripheryImmutableState
          • IPeripheryPayments
          • IPeripheryPaymentsWithFee
          • IPoolInitializer
          • IQuoter
          • IQuoterV2
          • ISelfPermit
          • ISwapRouter
          • ITickLens
          • external
            • IERC1271
            • IERC20PermitAllowed
            • IWETH9
        • Lens
          • Quoter
          • QuoterV2
          • TickLens
        • Libraries
          • Base64
          • BytesLib
          • CallbackValidation
          • ChainId
          • HexStrings
          • LiquidityAmounts
          • NFTDescriptor
          • NFTSVG
          • OracleLibrary
          • Path
          • PoolAddress
          • PoolTicksCounter
          • PositionKey
          • TokenRatioSortOrder
          • TransferHelper
          • WeightedOracleLibrary
        • NonfungiblePositionManager
        • NonfungibleTokenPositionDescriptor
        • SwapRouter
        • V3Migrator
      • Deployment Addresses
      • Error Codes
Powered by GitBook
On this page
  1. Developers
  2. Technical Reference
  3. Core
  4. Libraries

BitMath

PreviousLibrariesNextFixedPoint128

Last updated 2 years ago

This library provides functionality for computing bit properties of an unsigned integer

Functions

mostSignificantBit

  function mostSignificantBit(
    uint256 x
  ) internal pure returns (uint8 r)

Returns the index of the most significant bit of the number, where the least significant bit is at index 0 and the most significant bit is at index 255

The function satisfies the property: x >= 2mostSignificantBit(x) and x < 2(mostSignificantBit(x)+1)

Parameters:

Name
Type
Description

x

uint256

the value for which to compute the most significant bit, must be greater than 0

Return Values:

Name
Type
Description

r

unit8

the index of the most significant bit

leastSignificantBit

  function leastSignificantBit(
    uint256 x
  ) internal pure returns (uint8 r)

Returns the index of the least significant bit of the number, where the least significant bit is at index 0 and the most significant bit is at index 255

The function satisfies the property: (x & 2leastSignificantBit(x)) != 0 and (x & (2(leastSignificantBit(x)) - 1)) == 0)

Name
Type
Description

x

uint256

the value for which to compute the least significant bit, must be greater than 0

Name
Type
Description

r

unit8

the index of the least significant bit

Parameters:

Return Values:

🛠️
​
​
​
​
​
​
​