public static float ToSingle(uint value) { UIntFloat uf = new UIntFloat(); uf.intValue = value; return(uf.floatValue); }
public static int BitConvertFloatToInt(float value) { var intfloat = new UIntFloat(); intfloat.FloatValue = value; return(intfloat.IntValue); }
/// <summary> /// Doubleの値をByte列に変換、ビッグエンディアンとして返す /// </summary> /// <param name="value">変換するdouble値</param> /// <returns>ビッグエンディアンのByte配列</returns> static public byte[] ToBytes(double value) { UIntFloat uif = new UIntFloat(); uif.doubleValue = value; ulong x = uif.longValue; byte a = (byte)((x >> 0) & 0xff); byte b = (byte)((x >> 8) & 0xff); byte c = (byte)((x >> 16) & 0xff); byte d = (byte)((x >> 24) & 0xff); byte e = (byte)((x >> 32) & 0xff); byte f = (byte)((x >> 40) & 0xff); byte g = (byte)((x >> 48) & 0xff); byte h = (byte)((x >> 56) & 0xff); if (System.BitConverter.IsLittleEndian) { return(new[] { h, g, f, e, d, c, b, a }); } else { return(new[] { a, b, c, d, e, f, g, h }); } }
static public float ToFloat(uint value) { UIntFloat uif = new UIntFloat(); uif.intValue = value; return(uif.floatValue); }
public static float BitConvertIntToFloat(int value) { var intfloat = new UIntFloat(); intfloat.IntValue = value; return(intfloat.FloatValue); }
static public double ToDouble(byte[] values) { ulong x = 0; if (System.BitConverter.IsLittleEndian) { x |= ((ulong)values[7] << 0); x |= ((ulong)values[6] << 8); x |= ((ulong)values[5] << 16); x |= ((ulong)values[4] << 24); x |= ((ulong)values[3] << 32); x |= ((ulong)values[2] << 40); x |= ((ulong)values[1] << 48); x |= ((ulong)values[0] << 56); } else { x |= ((ulong)values[0] << 0); x |= ((ulong)values[1] << 8); x |= ((ulong)values[2] << 16); x |= ((ulong)values[3] << 24); x |= ((ulong)values[4] << 32); x |= ((ulong)values[5] << 40); x |= ((ulong)values[6] << 48); x |= ((ulong)values[7] << 56); } UIntFloat uif = new UIntFloat(); uif.longValue = x; return(uif.doubleValue); }
public static float ToSingle(uint value) { UIntFloat uf = default; uf.IntValue = value; return(uf.FloatValue); }
public static double ToDouble(ulong value) { UIntFloat uf = default; uf.LongValue = value; return(uf.DoubleValue); }
public static float ToSingle(uint value) { UIntFloat uIntFloat = default(UIntFloat); uIntFloat.intValue = value; return(uIntFloat.floatValue); }
public static double ToDouble(ulong value) { UIntFloat uIntFloat = default(UIntFloat); uIntFloat.longValue = value; return(uIntFloat.doubleValue); }
static public double ToDouble(ulong value) { UIntFloat uif = new UIntFloat(); uif.longValue = value; return(uif.doubleValue); }
public static float GetSingle(byte b1, byte b2, byte b3, byte b4) { var cv = new UIntFloat { IntValue = (uint)((b4 << 24) | (b3 << 16) | (b2 << 8) | b1) }; return(cv.FloatValue); }
public static float GetFloatFromInt(this uint value) { UIntFloat union = new UIntFloat() { uintValue = (uint)value }; return((int)union.floatValue); }
/// <summary> /// Write float /// </summary> public unsafe void Write(float value) { UIntFloat conversion = new UIntFloat() { floatValue = value }; Write(conversion.intValue); }
public static float ReadSingle(this NetworkReader reader) { var converter = new UIntFloat { intValue = reader.ReadUInt32() }; return(converter.floatValue); }
public static uint GetUIntFromFloat(this float value) { UIntFloat union = new UIntFloat() { floatValue = value }; return(union.uintValue); }
public static void SetSingle(out byte b1, out byte b2, out byte b3, out byte b4, float data) { var cv = new UIntFloat { FloatValue = data }; b1 = (byte)((cv.IntValue >> 0) & 0xFF); b2 = (byte)((cv.IntValue >> 8) & 0xFF); b3 = (byte)((cv.IntValue >> 16) & 0xFF); b4 = (byte)((cv.IntValue >> 24) & 0xFF); }
/// <summary> /// Floatの値をByte列に変換、ビッグエンディアンとして返す /// </summary> /// <param name="value">変換するfloat値</param> /// <returns>ビッグエンディアンのByte配列</returns> static public byte[] ToBytes(float value) { UIntFloat uif = new UIntFloat(); uif.floatValue = value; uint x = uif.intValue; byte a = (byte)((x >> 0) & 0xff); byte b = (byte)((x >> 8) & 0xff); byte c = (byte)((x >> 16) & 0xff); byte d = (byte)((x >> 24) & 0xff); if (System.BitConverter.IsLittleEndian) { return(new[] { d, c, b, a }); } else { return(new[] { a, b, c, d }); } }
static public float ToFloat(byte[] values) { uint x = 0; if (System.BitConverter.IsLittleEndian) { x |= ((uint)values[3] << 0); x |= ((uint)values[2] << 8); x |= ((uint)values[1] << 16); x |= ((uint)values[0] << 24); } else { x |= ((uint)values[0] << 0); x |= ((uint)values[1] << 8); x |= ((uint)values[2] << 16); x |= ((uint)values[3] << 24); } UIntFloat uif = new UIntFloat(); uif.intValue = x; return(uif.floatValue); }