In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the example analysis of Convert class solutions in C#, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
You have a string that contains binary, octal, decimal, or hexadecimal numbers. You need to convert it to an equivalent value and represent it in decimal system.
C # Convert class workaround:
To convert a number from another base to a decimal number, simply use the overloaded static method Convert.ToInt32 of the C # Convert class:
String base2 = "11"; string base8 = "17"; string base10 = "110"; string base16 =" 11FF "; Console.WriteLine (" Convert.ToInt32 (base2, 2) = "+ Convert.ToInt32 (base2, 2)); Console.WriteLine (" Convert.ToInt32 (base8, 8) = "+ Convert.ToInt32 (base8, 8)); Console.WriteLine (" Convert.ToInt32 (base10, 10) = "+ Convert.ToInt32 (base10, 10)) Console.WriteLine ("Convert.ToInt32 (base16, 16) =" + Convert.ToInt32 (base16, 16))
The code produces this output:
Convert.ToInt32 (base2, 2) = 3 Convert.ToInt32 (base8, 8) = 15 Convert.ToInt32 (base10, 10) = 110 Convert.ToInt32 (base16, 16) = 4607
Discussion:
The static method Convert.ToInt32 takes two parameters, a string containing a number and an integer representing the numeric base. This function then converts the number string to a decimal integer.
Other static functions of the C # Convert class, such as ToByte,ToInt64 and ToInt16, have similar overloads, which accept a number of string types and an integer that represents the numeric base. However, these methods can only convert binary, octal, decimal, or hexadecimal numbers. They can only convert these numbers to decimal numbers. However, the ToString of any type of numeric value can be converted to string.
Thank you for reading this article carefully. I hope the article "sample Analysis of Convert Solutions in C#" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un