0

I am trying to understand why BITWISE AND (&) operator used instead of LOGICAL AND (&&) operator in ERC 1155 implementation.

Link - https://github.com/enjin/erc-1155/blob/master/contracts/ERC1155MixedFungible.sol

Just for more clarity, I am also stating the code here.

If someone can explain with help of an example, that would be great.

function isNonFungible(uint256 _id) public pure returns(bool) { return _id & TYPE_NF_BIT == TYPE_NF_BIT; } function isFungible(uint256 _id) public pure returns(bool) { return _id & TYPE_NF_BIT == 0; } function getNonFungibleIndex(uint256 _id) public pure returns(uint256) { return _id & NF_INDEX_MASK; } function getNonFungibleBaseType(uint256 _id) public pure returns(uint256) { return _id & TYPE_MASK; } 

1 Answer 1

3

They do so because the values manipulated TYPE_NF_BIT, NF_INDEX_MASK and TYPE_MASK are used as bit flags or bit masks.

That way they can encode several pieces of information in a single uint256 _id.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.