Skip to main content
added 55 characters in body
Source Link
Yilmaz
  • 1.7k
  • 1
  • 10
  • 26

this operation uint256 pow2 = d & -d is from FullMath.sol

 function fullDiv(
        uint256 l,
        uint256 h,
        uint256 d
    ) private pure returns (uint256) {
        uint256 pow2 = d & -d;   
        d /= pow2;      
        .....
    }

I tested this operation with 20 and -20.

    00010100 = 20
    11101100 = -20

its bitwise and result is (If I am not mistaken so far)

 00010100 & 11101100=00000100

Why is this significant? Uniswap named variable AS pow2 but all the numbers from binary are already the power of 2. After the bitwise operation, d is divided by pow2pow2=d & -d

Its bitwise operation. I am trying to understand, what is the point of this division.

this operation uint256 pow2 = d & -d is from FullMath.sol

 function fullDiv(
        uint256 l,
        uint256 h,
        uint256 d
    ) private pure returns (uint256) {
        uint256 pow2 = d & -d;   
        d /= pow2;      
        .....
    }

I tested this operation with 20 and -20.

    00010100 = 20
    11101100 = -20

its bitwise and result is (If I am not mistaken so far)

 00010100 & 11101100=00000100

Why is this significant? Uniswap named variable pow2 but all the numbers from binary are the power of 2. After the bitwise operation, d is divided by pow2

Its bitwise operation

this operation uint256 pow2 = d & -d is from FullMath.sol

 function fullDiv(
        uint256 l,
        uint256 h,
        uint256 d
    ) private pure returns (uint256) {
        uint256 pow2 = d & -d;   
        d /= pow2;      
        .....
    }

I tested this operation with 20 and -20.

    00010100 = 20
    11101100 = -20

its bitwise and result is (If I am not mistaken so far)

 00010100 & 11101100=00000100

Why is this significant? Uniswap named variable AS pow2 but all the numbers from binary are already the power of 2. After the bitwise operation, d is divided by pow2=d & -d. I am trying to understand, what is the point of this division.

added 92 characters in body
Source Link
Yilmaz
  • 1.7k
  • 1
  • 10
  • 26

this operation uint256 pow2 = d & -d is from FullMath.sol

 function fullDiv(
        uint256 l,
        uint256 h,
        uint256 d
    ) private pure returns (uint256) {
        uint256 pow2 = d & -d;   
        d /= pow2;      
        .....
    }

I tested this operation with 20 and -20.

    00010100 = 20
    11101100 = -20

its bitwise and result is (If I am not mistaken so far)

 00010100 & 11101100=00000100

Why is this significant? Uniswap named variable pow2 but all the numbers from binary isare the power of 2. After the bitwise operation, d is divided by pow2

Its bitwise operation

this operation uint256 pow2 = d & -d is from FullMath.sol

 function fullDiv(
        uint256 l,
        uint256 h,
        uint256 d
    ) private pure returns (uint256) {
        uint256 pow2 = d & -d;
        .....
    }

I tested this operation with 20 and -20.

    00010100 = 20
    11101100 = -20

its bitwise and result is (If I am not mistaken so far)

 00010100 & 11101100=00000100

Why is this significant? Uniswap named variable pow2 but all the numbers from binary is power of 2.

Its bitwise operation

this operation uint256 pow2 = d & -d is from FullMath.sol

 function fullDiv(
        uint256 l,
        uint256 h,
        uint256 d
    ) private pure returns (uint256) {
        uint256 pow2 = d & -d;   
        d /= pow2;      
        .....
    }

I tested this operation with 20 and -20.

    00010100 = 20
    11101100 = -20

its bitwise and result is (If I am not mistaken so far)

 00010100 & 11101100=00000100

Why is this significant? Uniswap named variable pow2 but all the numbers from binary are the power of 2. After the bitwise operation, d is divided by pow2

Its bitwise operation

Source Link
Yilmaz
  • 1.7k
  • 1
  • 10
  • 26

"bitwise and" operation between value and its two's component

this operation uint256 pow2 = d & -d is from FullMath.sol

 function fullDiv(
        uint256 l,
        uint256 h,
        uint256 d
    ) private pure returns (uint256) {
        uint256 pow2 = d & -d;
        .....
    }

I tested this operation with 20 and -20.

    00010100 = 20
    11101100 = -20

its bitwise and result is (If I am not mistaken so far)

 00010100 & 11101100=00000100

Why is this significant? Uniswap named variable pow2 but all the numbers from binary is power of 2.

Its bitwise operation