Skip to content

Neatest way to check the parity of a BigNumber #1572

Answered by ricmoo
PaulRBerg asked this question in Q&A
Discussion options

You must be logged in to vote

Keep in mind == doesn't work on BigNumbers, you would need x.mod(2).eq(BigNumber.from(0)).

But either of these is prolly better:

  • x.mod(2).isZero()
  • x.mod(2).eq(0)
  • x.and(1).isZero()
  • x.and(1).eq(0)

Hope that helps. :)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@PaulRBerg
Comment options

Answer selected by PaulRBerg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants