NEWTON
Asked
9 months ago
12
views
0
I am looking for n % 2 = 0 operation
ㅤ This question was originally posted on Triality
0
from starkware.cairo.common.math import unsigned_div_rem
func is_even{range_check_ptr}(x) -> (res):
let (_, is_odd) = unsigned_div_rem(x, 2)
return (res=1 - is_odd)
end
ㅤ This answer was originally posted on Triality
answered
9 months ago
0
You can use bitwise operations to check this
bitwise_and(number, 1) == 0 and #where number is your variable you are testing if even
This is a code snippet to illustrate the point well
%builtins bitwise
from starkware.cairo.common.bitwise import bitwise_and
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
func main{bitwise_ptr : BitwiseBuiltin*}():
let (temp) = bitwise_and(3, 1)
assert temp = 1
let (temp) = bitwise_and(4, 1)
assert temp = 0
return ()
end
ㅤ This answer was originally posted on Triality
answered
9 months ago
Is anyone experiencing slowness on goerli StarkNet?
Do I need to learn cairo to develop on starknet?
How to transpile multiple contracts at once using warp?
How do I connect my DAPP to Starknet testnet using starknetjs?
Cairo: Else if statement
How to check if a contract has been deployed at a certain address in cairo?
Why should I run a Pathfinder node?