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. Hex conversion help

Hex conversion help

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
5 Posts 3 Posters 1 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.
  • W Offline
    W Offline
    Weiye Chen
    wrote on last edited by
    #1

    Can someone advise me on how to convert hex conversion in C#? I am currently trying to get the string in a textbox, say "20" and convert it to its hex form 14, and then display it onto another textbox. Weiye, Chen When pursuing your dreams, don't forget to enjoy your life...

    K G 2 Replies Last reply
    0
    • W Weiye Chen

      Can someone advise me on how to convert hex conversion in C#? I am currently trying to get the string in a textbox, say "20" and convert it to its hex form 14, and then display it onto another textbox. Weiye, Chen When pursuing your dreams, don't forget to enjoy your life...

      K Offline
      K Offline
      KingTermite
      wrote on last edited by
      #2

      From help (I did something similar to this) : Console.Write("{0:X}", 250); I'm not sure if you can do that directly to a string or if you need to use a StringBuffer class like I did. This is some code how I retreived color codes in individual colors (in bytes) and converted them to hex strings. StringBuilder oBuffer = new StringBuilder(); string strColorCode = ""; byte byRed = 0; byte byGreen = 0; byte byBlue = 0; // Selected color can now be retreived by RGB components byRed = oColor.R; byGreen = oColor.G; byBlue = oColor.B; // Format string to get hex number for color strColorCode = "{0:x2}{1:x2}{2:x2}"; oBuffer.AppendFormat(strColorCode, byRed, byGreen, byBlue); return oBuffer.ToString();


      There are only 10 types of people in this world....those that understand binary, and those that do not.

      W 1 Reply Last reply
      0
      • K KingTermite

        From help (I did something similar to this) : Console.Write("{0:X}", 250); I'm not sure if you can do that directly to a string or if you need to use a StringBuffer class like I did. This is some code how I retreived color codes in individual colors (in bytes) and converted them to hex strings. StringBuilder oBuffer = new StringBuilder(); string strColorCode = ""; byte byRed = 0; byte byGreen = 0; byte byBlue = 0; // Selected color can now be retreived by RGB components byRed = oColor.R; byGreen = oColor.G; byBlue = oColor.B; // Format string to get hex number for color strColorCode = "{0:x2}{1:x2}{2:x2}"; oBuffer.AppendFormat(strColorCode, byRed, byGreen, byBlue); return oBuffer.ToString();


        There are only 10 types of people in this world....those that understand binary, and those that do not.

        W Offline
        W Offline
        Weiye Chen
        wrote on last edited by
        #3

        I just found out how to do the conversion, thanks to your format string : strColorCode = "{0:x2}{1:x2}{2:x2}"; This is what i did : short sh = System.Convert.ToInt16(tbTextBox.Text, 10); tbTextBox2.Text = String.Format("{0:x2}", sh); Weiye, Chen When pursuing your dreams, don't forget to enjoy your life...

        1 Reply Last reply
        0
        • W Weiye Chen

          Can someone advise me on how to convert hex conversion in C#? I am currently trying to get the string in a textbox, say "20" and convert it to its hex form 14, and then display it onto another textbox. Weiye, Chen When pursuing your dreams, don't forget to enjoy your life...

          G Offline
          G Offline
          gek_at
          wrote on last edited by
          #4

          [using SWF;] int i = 20; txtBox1.Text = i.ToString(); txtBox2.Text = i.ToString("x"); Greets, Daniel

          W 1 Reply Last reply
          0
          • G gek_at

            [using SWF;] int i = 20; txtBox1.Text = i.ToString(); txtBox2.Text = i.ToString("x"); Greets, Daniel

            W Offline
            W Offline
            Weiye Chen
            wrote on last edited by
            #5

            Thanks... This seems like a more straight forward method :-D Weiye, Chen When pursuing your dreams, don't forget to enjoy your life...

            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