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 Hexa Decimal to to Decimal

Convert Hexa Decimal to to Decimal

Scheduled Pinned Locked Moved C#
csharptutorialquestion
10 Posts 8 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.
  • U Offline
    U Offline
    User 3055467
    wrote on last edited by
    #1

    Hi, can any one tell me how to Convert a hexa Decimal value(4363A00E) to decimal(in the format of 123.34567)in C#.Is there any direct function to do this? Thanks in advance

    V OriginalGriffO T C 4 Replies Last reply
    0
    • U User 3055467

      Hi, can any one tell me how to Convert a hexa Decimal value(4363A00E) to decimal(in the format of 123.34567)in C#.Is there any direct function to do this? Thanks in advance

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      Here you go[^]

      Cheers, Vikram.

      Current activities: Films: The classic Pink Panther series TV series: Friends, season 3 Books: Liar's Poker, by Michael Lewis.


      Carpe Diem.

      M 1 Reply Last reply
      0
      • U User 3055467

        Hi, can any one tell me how to Convert a hexa Decimal value(4363A00E) to decimal(in the format of 123.34567)in C#.Is there any direct function to do this? Thanks in advance

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Member 3057887 wrote:

        Convert a hexa Decimal value(4363A00E) to decimal(in the format of 123.34567)

        Why would you want to convert a hex value to a float? Unless it is the hex representation of the internal value of a float? Or are you just to lazy to tell us what you want to achieve? Give information, including what you have tried, and you are more likely to get a helpful response.

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • U User 3055467

          Hi, can any one tell me how to Convert a hexa Decimal value(4363A00E) to decimal(in the format of 123.34567)in C#.Is there any direct function to do this? Thanks in advance

          T Offline
          T Offline
          tom572007
          wrote on last edited by
          #4

          String hexNumber = "4363A00E"; int i = Int32.Parse(hexNumber, System.Globalization.NumberStyles.HexNumber); Why do you want to display it in decimal? You can't create decimal with an hexa...

          U 1 Reply Last reply
          0
          • T tom572007

            String hexNumber = "4363A00E"; int i = Int32.Parse(hexNumber, System.Globalization.NumberStyles.HexNumber); Why do you want to display it in decimal? You can't create decimal with an hexa...

            U Offline
            U Offline
            User 3055467
            wrote on last edited by
            #5

            Hi, Thanks for replying so soon. I am doing an application involving serial Port.I am getting data from Serial Port in Hexa decimal format(for eg.436300E).I need to convert that into floating point(eg.123.34). Thanks

            OriginalGriffO R A 3 Replies Last reply
            0
            • U User 3055467

              Hi, Thanks for replying so soon. I am doing an application involving serial Port.I am getting data from Serial Port in Hexa decimal format(for eg.436300E).I need to convert that into floating point(eg.123.34). Thanks

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              Data from a serial port generaly comes in as a stream of bytes, and are not amenable to conversion to float directly - parse probably wont work. I assume your data is coming from a data logger or sillyscope or similar? You will have to give more detail on the incomming data stream before anyone can help you much.

              No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • U User 3055467

                Hi, Thanks for replying so soon. I am doing an application involving serial Port.I am getting data from Serial Port in Hexa decimal format(for eg.436300E).I need to convert that into floating point(eg.123.34). Thanks

                R Offline
                R Offline
                Rob Philpott
                wrote on last edited by
                #7

                Hexidecimal notation usually is always involved with integer values. To convert to a float, you'd need to convert to an integer first and then move into the floating point world. Your hexidecimal representation, is it fixed point or floating point?

                Regards, Rob Philpott.

                1 Reply Last reply
                0
                • V Vikram A Punathambekar

                  Here you go[^]

                  Cheers, Vikram.

                  Current activities: Films: The classic Pink Panther series TV series: Friends, season 3 Books: Liar's Poker, by Michael Lewis.


                  Carpe Diem.

                  M Offline
                  M Offline
                  Michael Bookatz
                  wrote on last edited by
                  #8

                  you really need to see this website. www.lmgtfy.com . It's much more informative

                  1 Reply Last reply
                  0
                  • U User 3055467

                    Hi, Thanks for replying so soon. I am doing an application involving serial Port.I am getting data from Serial Port in Hexa decimal format(for eg.436300E).I need to convert that into floating point(eg.123.34). Thanks

                    A Offline
                    A Offline
                    Anthony Mushrow
                    wrote on last edited by
                    #9

                    In that case what you need to do is use the BitConverter which will convert a set of bytes into another data type. To get your bytes (hopefully 4 of them) to a float you need to use ToSingle So you'd have:

                    byte[] data = ...
                    float myFloat = BitConverter.ToSingle(data)

                    ToSingle also takes a second parameter (all of the functions in BitConverter do). The second parameter is the offset in the set of bytes where your float starts. That way if you had a stream you could just read all of the bytes out and then work your way through; rather than copying out 2 or 4 bytes to some other array all the time. EDIT: You say your getting the data in hex format, I assume your just getting bytes which are usually represented as hex. If you are actually getting a string from the port then you'll need to convert that back into a set of bytes,.

                    My current favourite word is: Delicious!

                    -SK Genius

                    Game Programming articles start -here[^]-

                    1 Reply Last reply
                    0
                    • U User 3055467

                      Hi, can any one tell me how to Convert a hexa Decimal value(4363A00E) to decimal(in the format of 123.34567)in C#.Is there any direct function to do this? Thanks in advance

                      C Offline
                      C Offline
                      CPallini
                      wrote on last edited by
                      #10

                      You may use a 'union' see [^]

                      [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit)]
                      struct TestUnion
                      {
                      [System.Runtime.InteropServices.FieldOffset(0)]
                      public UInt32 i;

                      [System.Runtime.InteropServices.FieldOffset(0)]
                      public Single s;
                      }

                      and then, for instance:

                      TestUnion tu = new TestUnion();
                      tu.i = UInt32.Parse("4363A00E", System.Globalization.NumberStyles.HexNumber);
                      Single s = tu.s;

                      However it gives 227.625214 as result (are you sure about the expected output?). :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      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