function BinToInt(Value: String): LongInt;
var i: Integer;
begin
Result:=0;
//remove leading zeros
while Copy(Value,1,1)='0' do
Value:=Copy(Value,2,Length(Value)-1);
//do the conversion
for i:=Length(Value) downto 1 do
if Copy(Value,i,1)='1' then
Result:=Result+(1 shl (i-1));
end;