Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Writing IBM Mainframe floating point

by sundialsvc4 (Abbot)
on Jul 21, 2018 at 03:51 UTC ( #1218984=note: print w/replies, xml ) Need Help??

in reply to Writing IBM Mainframe floating point looks like a person who has already done this same bit of bit-twiddling in Perl ... but note the article that is referenced in the post appears to no longer exist.

Or, well, I might be exactly-wrong in that this function apparently converts from IBM format.   Still, I think it would point fairly directly to how to go the other way. also published this little jewel, although it is for JavaScript and doesn’t cover Infinity, NAN, etc.:

function ibm2js(buffer) { var sign = buffer[0] >> 7 var exponent = buffer[0] & 0x7f var fraction = 0 function bit(buffer, bit) { return buffer[Math.floor(bit / 8)] >> (7 - (bit % 8)) & 1 } for (var i = 0; i < 24; i++) { fraction += bit(buffer, 8 + i) / (2 << i) } return (1 - 2 * sign) * Math.pow(16.0, exponent - 64) * fraction }

2018-07-23 Athanasius linkified both links

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1218984]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2019-12-16 00:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found