What is IEEE754Lib?

IEEE754Lib is a small Java library that supports encoding and decoding floating point numbers using IEEE-754 bit streams. Numbers are represented as Java objects that are independent of encoding formats.

Supported Formats

Basic Formats

Encoding, decoding, and conversion of all basic interchange formats is supported:

Name Common name Exponent bits Significand bits Exponent bias
binary16 Half 5 10 15
binary32 Single 8 23 127
binary64 Double 11 52 1,023
binary128 Quadruple 15 112 16,383
binary256 Octuple 19 236 262,143

Arbitrary Formats

Arbitrary formats are supported by providing custom values for:

Usage Examples

Reading Quadruple-Precision (binary128) from a Byte Array

byte[] quadBytes; // Input (16 bytes)
IEEE754 number = IEEE754.decode(IEEE754Format.QUADRUPLE, 
double converted = number.doubleValue();

Writing Double-Precision (binary64) to an OutputStream

IEEE754 number; // Input
OutputStream os; // Output
number.toBits(IEEE754Format.DOUBLE, BitUtils.wrapSink(os));

Reading Arbitrary-Precision from a Byte Array

byte[] quadBytes; // Input (16 bytes)
IEEE754Format format = new IEEE754Format(
		11,                      // Exponent bit-count
		52,                      // Significand bit-count
		BigInteger.valueOf(1023) // Exponent bias
IEEE754 number = IEEE754.decode(format, BitUtils.wrapSource(quadBytes));