Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Convert Hex strings to Long/Decimals?

Convert Hex strings to Long/Decimals?

Scheduled Pinned Locked Moved C#
helpcsharpcomxmltutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chua Wen Ching
    wrote on last edited by
    #1

    I have a problem. But on .NET 1.1 My Scenario: Actually I will have a string of hexadecimals read from a xml file. Then from the hexadecimals, i will add 1 value whenever i made any modifications. But just i do not how to get started. It is like an incremental hexadecimals. I have a string of hex. string strHex = "0100000000FF"; I want to convert this Hex to decimals, just like the windows calculate, when you type FF in Hex and click on Dec radio button, it will change to 255. I tried string.Format("{0:d}", strHex); I tried Convert.ToDecimal or Convert.ToInt64 But i still cannot find a solution? ---- I know how to convert long to hex. Like this. for (long x = 000000000000; x <= 281474976710655; x++) { Console.WriteLine(string.Format("{0:x12}", x)); Console.ReadLine(); } But i do not know how to do the opposite? Anyone can help me please? Thanks. Regards, Chua Wen Ching Visit us at http://www.necoders.com

    S 1 Reply Last reply
    0
    • C Chua Wen Ching

      I have a problem. But on .NET 1.1 My Scenario: Actually I will have a string of hexadecimals read from a xml file. Then from the hexadecimals, i will add 1 value whenever i made any modifications. But just i do not how to get started. It is like an incremental hexadecimals. I have a string of hex. string strHex = "0100000000FF"; I want to convert this Hex to decimals, just like the windows calculate, when you type FF in Hex and click on Dec radio button, it will change to 255. I tried string.Format("{0:d}", strHex); I tried Convert.ToDecimal or Convert.ToInt64 But i still cannot find a solution? ---- I know how to convert long to hex. Like this. for (long x = 000000000000; x <= 281474976710655; x++) { Console.WriteLine(string.Format("{0:x12}", x)); Console.ReadLine(); } But i do not know how to do the opposite? Anyone can help me please? Thanks. Regards, Chua Wen Ching Visit us at http://www.necoders.com

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      You need to manually loop through your Hex string, a byte at a time and convert it to decimal. Like this

      byte []hexValues = new byte[text.Length /3 + 1];

      int index = 0;
      for (int i = 0; i

      Regards
      Senthil
      _____________________________
      My Blog | My Articles | WinMacro

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups