public static double ConvertToDouble(this uint input) { double output; output = Double.FromByteArray(DWord.ToByteArray(input)); return(output); }
private static object GetPropertyValue(Type propertyType, byte[] bytes, ref double numBytes) { object value = null; switch (propertyType.Name) { case "Boolean": // get the value int bytePos = (int)Math.Floor(numBytes); int bitPos = (int)((numBytes - (double)bytePos) / 0.125); if ((bytes[bytePos] & (int)Math.Pow(2, bitPos)) != 0) { value = true; } else { value = false; } numBytes += 0.125; break; case "Byte": numBytes = Math.Ceiling(numBytes); value = (byte)(bytes[(int)numBytes]); numBytes++; break; case "Int16": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten ushort source = Word.FromBytes(bytes[(int)numBytes + 1], bytes[(int)numBytes]); value = source.ConvertToShort(); numBytes += 2; break; case "UInt16": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten value = Word.FromBytes(bytes[(int)numBytes + 1], bytes[(int)numBytes]); numBytes += 2; break; case "Int32": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten uint sourceUInt = DWord.FromBytes(bytes[(int)numBytes + 3], bytes[(int)numBytes + 2], bytes[(int)numBytes + 1], bytes[(int)numBytes + 0]); value = sourceUInt.ConvertToInt(); numBytes += 4; break; case "UInt32": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten value = DWord.FromBytes( bytes[(int)numBytes], bytes[(int)numBytes + 1], bytes[(int)numBytes + 2], bytes[(int)numBytes + 3]); numBytes += 4; break; case "Double": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten value = Double.FromByteArray( new byte[] { bytes[(int)numBytes], bytes[(int)numBytes + 1], bytes[(int)numBytes + 2], bytes[(int)numBytes + 3] }); numBytes += 4; break; case "Single": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten value = Single.FromByteArray( new byte[] { bytes[(int)numBytes], bytes[(int)numBytes + 1], bytes[(int)numBytes + 2], bytes[(int)numBytes + 3] }); numBytes += 4; break; default: var propClass = Activator.CreateInstance(propertyType); numBytes = FromBytes(propClass, bytes, numBytes); value = propClass; break; } return(value); }