Town Field Poem:
——— Dream who feel, the water month Build blog. Baiqian tribulation, only know the vicissitudes of the world.
——— today holds the Buddhist language, the technology is boundless willing to learn. Willing to do what you learn, cast a conscience blog.
——————————————————————————————————————————
1 Code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceConsoleApplication158 {9 class ProgramTen { One Static voidMain (string[] args) A { -Console.WriteLine ("Your turn:"); - stringValue =console.readline (); the - //separating strings, dividing by decimal point - string[] values = value. Split (New Char[] {'.'}, stringsplitoptions.removeemptyentries); - + //A string that stores the fractional part - stringDecimalspart = values[1]; + //string that stores the integer part A stringIntegerpart = values[0]; at - //Binary decimal Part out of the 10 binary number must be a double type of - DoubleSumofdecimalspart =0.0; - for(inti =0; i < decimalspart.length; i++) - { - //Decimalspart[i] is a char type, so add a ToString in //in the initial stage of the algorithm design, do not write a long formula with multiple variables, - //each variable that is to be Bashi is named separately, and then debugging can detect which variable is the problem to //int itemp = Convert.ToInt32 (Decimalspart[i]. ToString ()); + -Sumofdecimalspart + = convert.todouble (Convert.ToInt32 (decimalspart[i). ToString ()) * MATH.POW (2,-(i+1))); the } * $ Panax Notoginseng intSumofintegerpart =0; - for(inti =0; i < integerpart.length; i++) the { + //Decimalspart[i] is a char type, so add a ToString A //in the initial stage of the algorithm design, do not write a long formula with multiple variables, the //each variable that is to be Bashi is named separately, and then debugging can detect which variable is the problem + //int itemp = Convert.ToInt32 (Decimalspart[i]. ToString ()); - $Sumofintegerpart + = Convert.ToInt32 (Convert.ToInt32 (integerpart[i). ToString ()) * MATH.POW (2, i)); $ } - -Console.Write ("Decimalspart:"); the Console.WriteLine (decimalspart); - WuyiConsole.Write ("Sumofdecimalspart:"); the Console.WriteLine (sumofdecimalspart); - WuConsole.Write ("Integerpart:"); - Console.WriteLine (integerpart); About $Console.Write ("Sumofintegerpart:"); - Console.WriteLine (sumofintegerpart); - -Console.Write ("Result:"); A //This is a concatenation of integers and fractional parts. + //unsigned binary decimal 111.101 corresponds to 7.625, the //Sumofintegerpart 7; Sumofdecimalspart 0.625 need to remove 0 before the decimal point -Console.WriteLine (Sumofintegerpart+sumofdecimalspart.tostring (). Substring (1)); $ Console.readkey (); the } the } the}
2 Show
——————————————————————————————————————————
The essence of the blog, in the technical part, more in the town yard a poem.
C # is a good language, worth studying hard.
If the content of the post can be improved, or even the wrong place, please leave a comment, I will try to correct, strive to cast a conscience blog.
Note: This article is only as a scientific research study, if I inadvertently violated your rights and interests, please be sure to timely inform, I will make corrections.
C # console Base unsigned binary decimals converted to decimal