Wasatch.NET 2.4.14
.NET application driver for Wasatch Photonics spectrometers
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
WasatchNET.FunkyFloat Class Reference

Converts to and from the weird unsigned 16-bit float format used by the CCD gain commands. More...

Static Public Member Functions

static ushort fromFloat (float f)
 convert a standard IEEE float into the MSB-LSB UInt16 used within the spectrometer for gain control
 
static float toFloat (ushort n)
 convert the MSB-LSB UInt16 used within the spectrometer for gain control into a standard single-precision IEEE float
 

Detailed Description

Converts to and from the weird unsigned 16-bit float format used by the CCD gain commands.

Every company has a legacy API decision that nobody can currently explain or defend, yet for support reasons cannot easily deprecate. For Wasatch Photonics, this is that class. Yes, CCD gain probably should have been a standard 32-bit float. Bear with us, and get your funk on.

This is basically an unsigned 16-bit float, with exactly eight bits of precision for the integral component (left of the decimal, stored in the MSB), and eight bits of precision for the fractional component (right of the decimal, in the LSB).

That is to say, the MSB (left of the decimal, in float representation) represents an integral value from 0-255 as does any byte, while the LSB represents a fractional value between 0/256 and 255/256. This allows the resulting fraction to take on any unsigned fractional value between 0.0 and 255 + 255/256, in 1/256 (0.004) increments.

Example: 0x01e6 is approximately equal to 1.9

   MSB       LSB
--------- ---------
0000 0001 1110 0110
        | |||| |||+ 0 * 1/256 = 0
        | |||| ||+- 1 * 1/128 = 0.0078125
        | |||| |+-- 1 * 1/64  = 0.015625
        | |||| +--- 0 * 1/32  = 0
        | |||+----- 0 * 1/16  = 0
        | ||+------ 1 * 1/8   = 0.125
        | |+------- 1 * 1/4   = 0.25
        | +-------- 1 * 1/2   = 0.5
        +---------- 1 * 1     = 1
                              ===========
                                1.8984375

Member Function Documentation

◆ fromFloat()

static ushort WasatchNET.FunkyFloat.fromFloat ( float  f)
inlinestatic

convert a standard IEEE float into the MSB-LSB UInt16 used within the spectrometer for gain control

Parameters
fsingle-precision IEEE float
Returns
a UInt16 in which the MSB is a standard 8-bit byte and the LSB represents 8 bits of decreasing fractional precision

◆ toFloat()

static float WasatchNET.FunkyFloat.toFloat ( ushort  n)
inlinestatic

convert the MSB-LSB UInt16 used within the spectrometer for gain control into a standard single-precision IEEE float

Parameters
nUInt16 in which the MSB is a standard 8-bit byte and the LSB represents 8 bits of decreasing fractional precision
Returns
single-precision IEEE float

The documentation for this class was generated from the following file: