/*-----------------------Helper functions-----------------------*/ /** * Translates a 32-bit floating point into an array of four bytes */ void FloatToBytes(float val, byte[] segments) { uFloat temp = new uFloat(); temp.val_f = val; segments[3] = (byte)((temp.val_l >> 24) & 0xff); segments[2] = (byte)((temp.val_l >> 16) & 0xff); segments[1] = (byte)((temp.val_l >> 8) & 0xff); segments[0] = (byte)((temp.val_l) & 0xff); }
/** * Translates an array of four bytes into a floating point */ float BytesToFloat(byte[] segments) { uFloat temp = new uFloat(); temp.val_l = (temp.val_l | (segments[3] & 0xff)) << 8; temp.val_l = (temp.val_l | (segments[2] & 0xff)) << 8; temp.val_l = (temp.val_l | (segments[1] & 0xff)) << 8; temp.val_l = (temp.val_l | (segments[0] & 0xff)); return(temp.val_f); }