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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to convert Bytes to Hex

How to convert Bytes to Hex

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
9 Posts 4 Posters 11 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.
  • S Offline
    S Offline
    srija
    wrote on last edited by
    #1

    Hello.. Actually, am working with Serial port interfacing(MFC) in WIN32. Iam using some library which i found while browsing, actually i need to have the output data in Hex but it is in BYTES, so my problem is, how to convert the data which is in BYTES to Hex. srija

    T J 2 Replies Last reply
    0
    • S srija

      Hello.. Actually, am working with Serial port interfacing(MFC) in WIN32. Iam using some library which i found while browsing, actually i need to have the output data in Hex but it is in BYTES, so my problem is, how to convert the data which is in BYTES to Hex. srija

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      by converting, you mean printing or storing ? hexadecimal is only a representation issue. bytes are stored as bits and can be see as 2 hex characters, but this doesn't affect the handling... what do you want exactly ?


      TOXCCT >>> GEII power
      [toxcct][VisualCalc 2.24][3.0 soon...]

      S 1 Reply Last reply
      0
      • S srija

        Hello.. Actually, am working with Serial port interfacing(MFC) in WIN32. Iam using some library which i found while browsing, actually i need to have the output data in Hex but it is in BYTES, so my problem is, how to convert the data which is in BYTES to Hex. srija

        J Offline
        J Offline
        John M Drescher
        wrote on last edited by
        #3

        :confused: I am a little confused on what you are trying to do. I assume the data is binary and you want to send strings of hex codes instead? Like this 0A 2F 3C 2B FC If so loop through the bytes and output them with string.Format("%02X",onebyte); John -- modified at 10:17 Monday 20th February, 2006

        1 Reply Last reply
        0
        • T toxcct

          by converting, you mean printing or storing ? hexadecimal is only a representation issue. bytes are stored as bits and can be see as 2 hex characters, but this doesn't affect the handling... what do you want exactly ?


          TOXCCT >>> GEII power
          [toxcct][VisualCalc 2.24][3.0 soon...]

          S Offline
          S Offline
          srija
          wrote on last edited by
          #4

          Thank you for your kind reply! Actually i need to store data as 02 00 01 00 31 15 12..., but how to write the data in Bytes? Hope you got my problem.

          T 1 Reply Last reply
          0
          • S srija

            Thank you for your kind reply! Actually i need to store data as 02 00 01 00 31 15 12..., but how to write the data in Bytes? Hope you got my problem.

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            but you want this within a string ? or this is a representation of the memory ??


            TOXCCT >>> GEII power
            [toxcct][VisualCalc 2.24][3.0 soon...]

            S 1 Reply Last reply
            0
            • T toxcct

              but you want this within a string ? or this is a representation of the memory ??


              TOXCCT >>> GEII power
              [toxcct][VisualCalc 2.24][3.0 soon...]

              S Offline
              S Offline
              srija
              wrote on last edited by
              #6

              Ya, i need it in a string!!!!

              T 1 Reply Last reply
              0
              • S srija

                Ya, i need it in a string!!!!

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                so the other guy already answered correctly...


                TOXCCT >>> GEII power
                [toxcct][VisualCalc 2.24][3.0 soon...]

                W 1 Reply Last reply
                0
                • T toxcct

                  so the other guy already answered correctly...


                  TOXCCT >>> GEII power
                  [toxcct][VisualCalc 2.24][3.0 soon...]

                  W Offline
                  W Offline
                  Wim Engberts
                  wrote on last edited by
                  #8

                  In C(++) use the standard formatting: char szTarget[128]; // (or any size you need) sprintf (szTarget,"%.2x %.2x %.2x.......", Byte1, Byte2, Byte3, ......); or CString strTarget; strTarget.Format ("%.2x %.2x %.2x.......", Byte1, Byte2, Byte3, ......); Success, William

                  T 1 Reply Last reply
                  0
                  • W Wim Engberts

                    In C(++) use the standard formatting: char szTarget[128]; // (or any size you need) sprintf (szTarget,"%.2x %.2x %.2x.......", Byte1, Byte2, Byte3, ......); or CString strTarget; strTarget.Format ("%.2x %.2x %.2x.......", Byte1, Byte2, Byte3, ......); Success, William

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #9

                    i'm not the one to say that... tell it to the guy who asked the question...


                    TOXCCT >>> GEII power
                    [toxcct][VisualCalc 2.24][3.0 soon...]

                    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