in vb6 using
private type udt1 long end type private type udt2 f single end type private function intbitstofloat(byval u long) double dim n1 udt1 n1.i = u dim n2 udt2 lset n2 = n1 intbitstofloat = n2.f end function i trying find equivalent in vb.net did not find any.
does know it? thank you.
i think 1 works, based on test values wikipedia:
<structlayout(layoutkind.explicit)> structure udt <fieldoffset(0)> dim integer <fieldoffset(0)> dim f single end structure function intbitstofloat(byval u integer) single dim x udt x.i = u return x.f end function edit
guess should have searched first! see this answer less hacky version, in vb.net be:
function intbitstofloat(byval u integer) single dim bytes = bitconverter.getbytes(u) return bitconverter.tosingle(bytes, 0) end function update
looks hack structure faster on pc - e.g. on 100,000,000 iterations in linqpad:
#1: 00:00:00.0553656 #2: 00:00:01.2785214
Comments
Post a Comment