Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
double to hex to double lose precision
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static string DblToHex(string dbl) { return string.Join("", BitConverter.ToString(BitConverter.GetBytes(Convert.ToDouble(dbl))).Split('-').Reverse()); } public static string HexToDbl(string hex) { return BitConverter.ToDouble(Enumerable.Range(0, hex.Length) .Where(x => x % 2 == 0) .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) .Reverse().ToArray(), 0).ToString("E17"); } public static void Main(string[] args) { string hex = "FFD1C05B1E2380B6"; string dbl = "-4,986180087444250E+307"; Console.WriteLine(HexToDbl(hex)); Console.WriteLine(DblToHex(HexToDbl(hex))); Console.WriteLine(DblToHex(dbl)); Console.WriteLine(HexToDbl(DblToHex(dbl))); } } }
run
|
edit
|
history
|
help
0
gh
pyramidalt
FileNameCharCheck
Events
(Sort)Rounding Magic - C#
matching parenthesis
Linear search vs. Binary search
work_laba#2
Func
enigma