NEWTON
Asked
6 months ago
7
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
6 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
6 months ago
Why does Starkware pedersen Hash Function split numbers in high and low bits
Cairo OR operator
Does anyone know how to print a uint256 in protostar tests?
Is there any simple way to concat two arrays with known sizes in Cairo?
how to return struct
How do I connect my DAPP to a Starknet node using starknetjs?
How do you check if a number is even in Cairo?