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. how can I read 4 hex characters from a textbox and put them in a uint?

how can I read 4 hex characters from a textbox and put them in a uint?

Scheduled Pinned Locked Moved C#
question
5 Posts 4 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.
  • B Offline
    B Offline
    Big Ralph
    wrote on last edited by
    #1

    I need to read 4 hexadecimal chars from a textbox and put them into a Uint how can I do that? BiG RaLpH

    R B Z 3 Replies Last reply
    0
    • B Big Ralph

      I need to read 4 hexadecimal chars from a textbox and put them into a Uint how can I do that? BiG RaLpH

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      See UInt32.TryParse()[^] /ravi

      This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • B Big Ralph

        I need to read 4 hexadecimal chars from a textbox and put them into a Uint how can I do that? BiG RaLpH

        B Offline
        B Offline
        Big Ralph
        wrote on last edited by
        #3

        I need to see if I can change the hex 2. ie: textbox2.text = "1212abab" the uint returned must be 1212 and another abab. BiG RaLpH

        L 1 Reply Last reply
        0
        • B Big Ralph

          I need to see if I can change the hex 2. ie: textbox2.text = "1212abab" the uint returned must be 1212 and another abab. BiG RaLpH

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, you could: 1. use long.TryParse() and then split the long in upper and lower halfs. 2. split the string in two parts, and use int.TryParse() on each of them. The second method may be more difficult since it may have to cope with varying string lengths when leading zeroes are omitted in the string. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


          1 Reply Last reply
          0
          • B Big Ralph

            I need to read 4 hexadecimal chars from a textbox and put them into a Uint how can I do that? BiG RaLpH

            Z Offline
            Z Offline
            zafersavas
            wrote on last edited by
            #5

            You can use uint num = Convert.ToUInt16(textBox1.Text, 16); If the textbox contains more than 4 letters and if you want to change each 4 letters in to their uint value, you should first write a text splitter which is very simple with string.substring() function. Best Regards Zafer

            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