GCD - TCL, error = cant use non-numeric string as operand as of &

98 Views Asked by At

im trying to write a gcd (Stein's algorithm) in TCl and i'm using '&' as a bitwise operand so i can check if the number is odd or even, by multiplying the number (bitwise) by 1 (result 0 is even, 1 is odd) when i run the code in linux using genus, it keeps giving me the error :

'can't use non-numeric strin as operand of '&' '

im very new to TCL, does anybody can help how to solve this?

Thanks in advance

i looked for an answer but i didnt really find...

1

There are 1 best solutions below

2
Chris Heithoff On

Please give the exact code which is causing your problem.

You're probably expressing a binary number incorrectly.

Here are some examples which show that expression a binary 1 as "b1" is not allowed because it should be "0b1", or just 1!

tcl8.6.8> expr {65 & 1}
1

tcl8.6.8> expr {64 & 1}
0

tcl8.6.8> expr {65 & "b1"}
can't use non-numeric string as operand of "&"

tcl8.6.8> expr {65 & "0b1"}
1