In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what method C # uses to generate BitConverter.ToString strings and then convert them back. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Byte [] bytTemp = System.Text.Encoding.Default.GetBytes ("String"); string str = System.BitConverter.ToString (bytTemp); Console.WriteLine (str); string [] strSplit = str.Split ('-'); byte [] bytTemp2 = new byte [strSplit.Length]; for (int I = 0; I < strSplit.Length; ionization +) bytTemp2 [I] = byte.Parse (strSplit [I], System.Globalization.NumberStyles.AllowHexSpecifier); string str2 = System.Text.Encoding.Default.GetString (bytTemp2); Console.WriteLine (str2)
Convert c#bitconverter.ToString to hexadecimal string
I use BitConverter.ToString (bytes) to convert a string to a hexadecimal string, and I further convert it to an integer or floating point number.
But the input stream consists of 0, indicating that the byte value is 0. So suppose I have an integer represented by two bytes of input, starting with position x, the first consisting of EE and the second byte of 00. Now when I use BitConverter.ToString (bytes,x,2). Replace (- ","), the output is EE00 with an integer value of 60928, but in this case, the output should be 238 bytes and EE is an integer.
But in other cases, 2 bytes may be EE01, and its integer value of 60929 is correct in this case.
How will any suggestions solve my problem?
Since some people say that this problem is confusing, I will repeat my question that I have a very long hexadecimal string as input. In hexadecimal string
1) the first 12 bytes represent a string. 2) the next 11 bytes also represent other strings. 3) the next byte represents an integer. 4) the next 3 bytes represent integers. 5) the next four bytes represent integers. 6) the next four bytes represent floating-point numbers. 7) the next 7 bytes represent a string. 8) the next five bytes represent integers.
So, for the fourth case, if the byte is ee 00 00, then I should ignore 0 and convert ee to an integer. But if it is ee00ee, then I should convert ee00ee to an integer. I follow the same pattern mentioned above every time.
My problem has been solved. I'm making Endianness's mistake. The data I received is EE 00, which I should use as 00 EE before converting to an integer. Thanks to all the people who provided me with the solution, and I'm sorry I missed this important issue.
PS:C# uses BitConverter.ToString (byte [] value) to convert the string with a horizontal bar "-" to remove the horizontal bar method.
Use BitConverter.ToString (byte [] value) .replace ("-", ") to remove the crossbar
About C # how to generate BitConverter.ToString strings and then convert them back to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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
© 2024 shulou.com SLNews company. All rights reserved.