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. hex to decimal

hex to decimal

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
4 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.
  • S Offline
    S Offline
    styve
    wrote on last edited by
    #1

    How do i convert for example 2B67 in base 16 to decimal in base 10?? There is no command in sprintf??

    P 1 Reply Last reply
    0
    • S styve

      How do i convert for example 2B67 in base 16 to decimal in base 10?? There is no command in sprintf??

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      can you send the code sippnet how you are stored the base16 data?


      P.R.A.K.A.S.H

      S 1 Reply Last reply
      0
      • P Prakash Nadar

        can you send the code sippnet how you are stored the base16 data?


        P.R.A.K.A.S.H

        S Offline
        S Offline
        styve
        wrote on last edited by
        #3

        I'm using libpcap, and capturing the header of each packet. While it is a udp header, I will get the source port, byte 1 and byte 2. I'm reading one byte at the time with get(), so I cat them into one string. Probably I have put myself in a hard position to convert the string with hexadecimal numbers to decimal code: int main(){ ... while(!inFile.eof) { inFile.get(bin); ... if(count == 35) { sprintf(port1, "02X", bin); } if(count == 36) { sprintf(port, "%s%02X", port1, bin); } }

        P 1 Reply Last reply
        0
        • S styve

          I'm using libpcap, and capturing the header of each packet. While it is a udp header, I will get the source port, byte 1 and byte 2. I'm reading one byte at the time with get(), so I cat them into one string. Probably I have put myself in a hard position to convert the string with hexadecimal numbers to decimal code: int main(){ ... while(!inFile.eof) { inFile.get(bin); ... if(count == 35) { sprintf(port1, "02X", bin); } if(count == 36) { sprintf(port, "%s%02X", port1, bin); } }

          P Offline
          P Offline
          Prakash Nadar
          wrote on last edited by
          #4

          i guess this should be apporch thing are ok but with slight modification.

          while(!inFile.eof)
          {
          inFile.get(bin);
          ...

          if(count == 35)
          {
          sprintf(port1, "&d", bin); // note the print format.
          }

          if(count == 36)
          {
          sprintf(port, "%s%d", port1, bin); //note the print format.
          }

          int no = atoi(port); //The addition.

          }


          P.R.A.K.A.S.H

          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