I want to compare two integer columns (filled with 1s and 0s) to each other with bitwise and, then count number of 1s and divide by length of column entries. I wrote a function, but not sure if it is right or how to create in in Monetdb from console.

create function BAnd(int a, int b)
returns float
begin
declare count int;
int length = floor(log10(abs(a))) + 1;
temp = a & b;
while (temp != 0) {
if (n % 10 == 1)
count++;
temp /= 10;
}
return count/length;
end;