/// <summary> /// Method for formatter number type double in to the number formatter binary /// </summary> /// <param name="inputNumberWithDoublePoint">source number</param> /// <returns>bunary number in string performance</returns> public static string FormatterDoubleToBinary(this double inputNumberWithDoublePoint) { var structForFormatter = new DoubleToLongStruct { DoubleTo8Byte = inputNumberWithDoublePoint }; var valueToBinary = structForFormatter.LongTo8Byte; var lengthResult = sizeof(long) * BIT_IN_BYTE; var reversResult = lengthResult; var resultArray = new StringBuilder(); for (int i = 0; i < lengthResult; i++) { var addNumber = ((valueToBinary & (1L << reversResult - 1)) == 0) ? (byte)0 : (byte)1; resultArray.Append(((valueToBinary & (1L << reversResult - 1)) == 0) ? (byte)0 : (byte)1); reversResult--; } return(resultArray.ToString()); }
/// <summary> /// Convert double to IEEE /// </summary> /// <param name="number"> /// The number /// </param> /// <returns> /// IEEE string /// </returns> public static string DoubleToBinary(this double number) { DoubleToLongStruct convert = new DoubleToLongStruct { Double64Bits = number }; long long64Bits = convert.Long64Bits(); string stringBits = ""; for (int i = 0; i < BITS; i++) { char bit; if ((long64Bits & 1) == 1) { bit = '1'; } else { bit = '0'; } stringBits = bit + stringBits; long64Bits >>= 1; } return(stringBits); }
/// <summary> /// The method makes it possible to obtain a string representation of a real value /// in the format IEEE 754 /// </summary> /// <param name="value">double value</param> /// <returns>string in IEEE 754</returns> public static string ToIeee754Double(this double value) { var tempStruct = new DoubleToLongStruct(value); long longValue = (long)tempStruct; return(longValue.LongToBitString()); }
public static string BitsRepresentationAsStringV3(this double value) { DoubleToLongStruct converter = new DoubleToLongStruct(); long asLong = converter.GetLongFromDouble(value); return(asLong.LongToBitsString()); }
/// <summary> /// Method of finding string binary representation of a real number. /// </summary> /// <param name="number">Source number.</param> /// <returns>Binary representation of number of type <see cref="string"/>. </returns> public static string DoubleToBinaryString(this double number) { long numberLong = new DoubleToLongStruct(number).Long64bits; StringBuilder result = new StringBuilder(); for (int i = 0; i < BitsInByte * 8; i++) { result.Insert(0, (numberLong & 1) == 1 ? "1" : "0"); numberLong >>= 1; } return(result.ToString()); }
/// <summary> /// Convert double to string IEEE 754 format. /// </summary> /// <param name="number"> Value to convert. </param> /// <returns> String representation in IEEE 754 format. </returns> public static string DoubleToBinaryString(this double number) { var tmp = new DoubleToLongStruct(number); var tmp2 = tmp.Long64bits; var result = new char[64]; for (var i = BITS_IN_BYTE * 8 - 1; i >= 0; i--) { result[i] = (tmp2 & 1) == 0 ? '0' : '1'; tmp2 >>= 1; } var results = new string(result); return(results); }
public static string DoubleToBinaryString(this double number) { var convert = new DoubleToLongStruct { double64bits = number }; StringBuilder builder = new StringBuilder(); long one = 1; for (int i = 0; i < SIZE; i++) { builder.Append((convert.long64bits & (one << SIZE - 1 - i)) != 0 ? '1' : '0'); } return(builder.ToString()); }
/// <summary> /// Extension method for converting double to binary /// </summary> /// <param name="number">Given double number to convert</param> /// <returns>Binary representation of given number</returns> public static string DoubleToBinaryString(this double number) { DoubleToLongStruct convertStruct = new DoubleToLongStruct { Double64bits = number }; long value = convertStruct.Long64bits; int bitsCount = (int)Math.Pow(BitsInBytes, 2); char[] result = new char[bitsCount]; result[0] = value < 0 ? '1' : '0'; for (int i = bitsCount - 2, j = 1; i >= 0; i--, j++) { result[j] = (value & (1L << i)) != 0 ? '1' : '0'; } return(new string(result)); }
/// <summary> /// Converts value to the binary string representation /// </summary> /// <param name="number"> The <see cref="System.Double"/> type's value to be converted </param> /// <returns> The string representing converted value </returns> public static string ToBinaryString(this double number) { var doubleStruct = new DoubleToLongStruct(number); long temp = doubleStruct.LongContainer; long pointer = 1; char[] array = new char[MAXBITS]; for (int i = array.Length - 1; i >= 0; i--) { array[i] = (temp & pointer) == 0 ? '0' : '1'; pointer <<= 1; } return(new string(array)); }
/// <summary> /// Converts given number to the binary representation /// </summary> /// <param name="input">Input number</param> public static string ToBinaryString(this double input) { DoubleToLongStruct convertStruct = new DoubleToLongStruct { Double64bits = input }; long value = convertStruct.Long64bits; int bitsCount = 64; char[] result = new char[bitsCount]; result[0] = value < 0 ? '1' : '0'; for (int i = bitsCount - 2, j = 1; i >= 0; i--, j++) { result[j] = (value & (1L << i)) != 0 ? '1' : '0'; } return(new string(result)); }
/// <summary> /// Converts double to its iee-754 string represntatiom /// </summary> /// <param name="number"></param> /// <returns></returns> public static string DoubleToBinaryString(this double number) { StringBuilder result = new StringBuilder(); long reminderOF2; DoubleToLongStruct doubleToLongStruct = new DoubleToLongStruct(); doubleToLongStruct.Double64Bits = number; long longNumber = doubleToLongStruct.Long64Bits; while (longNumber > 0) { reminderOF2 = longNumber % 2; number /= 2; result.Append(reminderOF2.ToString()); } return(result.ToString()); }
/// <summary> /// Doubles to binary string. /// </summary> /// <param name="number">The number.</param> /// <returns>Returns string which represents binary representation of double in the format IEEE 754</returns> public static string DoubleToBinaryString(this double number) { const long mask = 1; int numberOfBits = 64; var binary = string.Empty; DoubleToLongStruct numberStruct = new DoubleToLongStruct { Double64Bits = number }; ulong long64Bits = numberStruct.Long64Bits; while (numberOfBits > 0) { binary = (long64Bits & mask) + binary; long64Bits >>= 1; numberOfBits--; } return(binary); }
/// <summary> /// Convert double to binary string according to IEEE 754 /// </summary> /// <param name="value">Input double number</param> /// <returns>Binary string</returns> public static string ConvertingDoubleToString(double value) { const int bitInByte = 8; DoubleToLongStruct doubleToLong = new DoubleToLongStruct(); doubleToLong.doubleValue = value; long longValue = doubleToLong.longValue; int iterations = bitInByte * sizeof(double); char[] doubleBits = new char[iterations]; for (int i = iterations - 1; i >= 0; i--) { doubleBits[i] = (longValue & 1) == 1 ? '1' : '0'; longValue >>= 1; } return(new string(doubleBits)); }
/// <summary> /// Converts from double to string of its binary representation /// </summary> /// <param name="number"> /// Double number /// </param> /// <returns> /// Binary representation /// </returns> public static string DoubleToBinaryString(this double number) { string binaryString = null; DoubleToLongStruct numberStruct = new DoubleToLongStruct(number); long numberLong = numberStruct.Long64bits; for (int i = 0; i < 8 * BITS_IN_BYTE; i++) { if ((numberLong & 1) == 1) { binaryString += "1"; } else { binaryString += "0"; } numberLong >>= 1; } return(Reverse(binaryString)); }
/// <summary> /// Transforms given 64bit floating-point number to its IEEE754 string representation. /// </summary> /// <param name="number">64bit floating-point number.</param> /// <returns>IEEE754 representation.</returns> public static string TransformToIEEE754(this double number) { var convertStruct = new DoubleToLongStruct { DoubleBitsRepresentation = number }; long value = convertStruct.LongBitsRepresentation; int bitsCount = sizeof(double) * BitsInByte; char[] result = new char[bitsCount]; long mask = 1; for (int i = 0; i < bitsCount; i++) { result[bitsCount - i - 1] = (value & mask) == 0 ? '0' : '1'; value >>= 1; } return(new string(result)); }
public static string DoubleTo64BinaryString(this double number) { DoubleToLongStruct bytes = new DoubleToLongStruct(); bytes.Double64bits = number; string binaryString = string.Empty; long bits = bytes.Long64bits; for (int n = 0; n < 64; n++) { if ((bits & 1) == 1) { binaryString += "1"; } else { binaryString += "0"; } bits >>= 1; } return(new string(binaryString.Reverse().ToArray())); }
/// <summary> /// Double to binary string. /// </summary> /// <param name="number">Source double number.</param> /// <returns>string that represents double bits</returns> public static string DoubleToBinaryString(this double number) { DoubleToLongStruct bytes = new DoubleToLongStruct(); bytes.Double64bits = number; string binaryString = string.Empty; long bits = bytes.Long64bits; for (int n = 0; n < BITS_IN_DOUBLE; n++) { if ((bits & 1) == 1) { binaryString = "1" + binaryString; } else { binaryString = "0" + binaryString; } bits >>= 1; } return(binaryString); }
public static string DoubleToBinary(this double number) { DoubleToLongStruct bits = new DoubleToLongStruct(number); return(bits.ToLong().ConvertToIEEE()); }
/// <summary> /// Convert double number in a binary code. /// </summary> /// <param name="number">Number to convert.</param> /// <returns>Binary code</returns> public static string ConvertDoubleToBinaryString(this double number) { DoubleToLongStruct numberInBinary = new DoubleToLongStruct(number); return(ConvertToBinaryCode(numberInBinary.Long64Bits)); }