One further fix was required to make this work for ascii chars >128.
function cvint4(s)
local a,b
b=asc(mid(s,4,1))
if (b>=128) then
b=b-128
a=0x80000000
else
a=0
end if
cvint4=asc(mid(s,1,1)) + asc(mid(s,2,1))*0x100 + asc(mid(s,3,1))*0x10000 + b*0x1000000 or a
asc(mid(s,4,1))*0x1000000
end function