Search code examples
logicarithmetic-expressionsnim-lang

Why 3 and 1 evaluates to 1 and 4 and 1 to 0 in nim-lang


Hi I'm new to nim and dont get how evaluations of arithmetics work?

3 and 1 # Outputs 1

and

4 and 1 # Outputs 0

Which logic is going on here?

Thanks


Solution

  • I think, in binary: 3 = 0b'11, 1 = 0b'01, so 3 and 1 = 0b'01, while 4 = 0b'100 and 1 = 0b'001, so 4 and 1 = 0b'00.