VBScript从文件流中读取浮点值

VBScript从文件流中读取浮点值,vbscript,ieee-754,Vbscript,Ieee 754,是否有任何纯VBS/wsh方法可以从构成IEEE浮点数的字符串中获取4个字节,并将其返回到单个类型的变量中? 我已经通过从字节中构建IEEE数字来实现了这一点,但是它的速度非常慢 function bintofloat (str,i) 'string, position dim n1,n2,exponent,mantissa,sign 'only normalized, does'nt detect infinity or NaN const m_sign= &

是否有任何纯VBS/wsh方法可以从构成IEEE浮点数的字符串中获取4个字节,并将其返回到单个类型的变量中? 我已经通过从字节中构建IEEE数字来实现了这一点,但是它的速度非常慢

function bintofloat (str,i)  'string, position
    dim n1,n2,exponent,mantissa,sign
    'only normalized, does'nt detect infinity or NaN
    const m_sign= &h80000000&, m_exp= &h7f80
    const d_exp= &h800000& , m_mant=&h7fffff&
    n1=asc(mid(str,i+3,1))* 256 + asc(mid(str,i+2,1))
    if n1 <0 then sign=-1 else sign=1
    n2 = ( asc(mid(str,i+2,1))* 256 + asc(mid(str,i+1,1)))* 256 + asc(mid(str,i,1))
    exponent = ((n1 and m_exp)/&h80)
    mantissa= (n2 and m_mant)
    if (exponent or mantissa) =0 then 
       bintofloat=0 
    else
     bintofloat =  sign* (mantissa or d_exp) * 2.^(exponent -150)
    end if   
end function
函数bintofloat(str,i)'string,position
尺寸n1,n2,指数,尾数,符号
'仅规格化,不检测无穷大或NaN
常数m_符号=&H8000000&,m_exp=&h7f80
常数d_exp=&h800000&,m_mant=&h7fffff&
n1=asc(中间(str,i+3,1))*256+asc(中间(str,i+2,1))

如果n1个字符的宽度超过一个字节,将导致算法出错。尽管在过去它对美国人有效,但在Win10设置为UTF时,它可能会失败。正如@david所说,在处理多字节字符时,这将中断。除非您专门处理ASCII,否则您还应该使用(请参见注释部分)。这是否回答了您的问题?