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 / C++ / MFC
  4. how to convert a integer from hex to decimal

how to convert a integer from hex to decimal

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
12 Posts 7 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.
  • X xiaohe521

    as subject thx I love Programming

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

    this is done automatically...

    int i = 0x57;
    ASSERT(i == 87);


    TOXCCT >>> GEII power
    [toxcct][VisualCalc]

    1 Reply Last reply
    0
    • X xiaohe521

      as subject thx I love Programming

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #3

      An integer is neither an hex or a decimal. It's an integer and that's it ! Now, it's representation (so you will print it on the screen, in a file, ...) can change from hew to decimal. But then, it's not converting an integer but converting a string.

      X 1 Reply Last reply
      0
      • X xiaohe521

        as subject thx I love Programming

        M Offline
        M Offline
        Marc Soleda
        wrote on last edited by
        #4

        hex, dec, oct are just ways to represent the same integer... ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.

        1 Reply Last reply
        0
        • C Cedric Moonen

          An integer is neither an hex or a decimal. It's an integer and that's it ! Now, it's representation (so you will print it on the screen, in a file, ...) can change from hew to decimal. But then, it's not converting an integer but converting a string.

          X Offline
          X Offline
          xiaohe521
          wrote on last edited by
          #5

          yes, the diffrent is the string's represent format, i know how to represent a integer to diffrent format string as char *_itoa( int value, char *string, int radix ); but int atoi( const char *string ); the function has only one param, no format param must i write a function to do this? I love Programming

          T C M N M 5 Replies Last reply
          0
          • X xiaohe521

            yes, the diffrent is the string's represent format, i know how to represent a integer to diffrent format string as char *_itoa( int value, char *string, int radix ); but int atoi( const char *string ); the function has only one param, no format param must i write a function to do this? I love Programming

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

            an integer is an integer !!!! it is stored as a serie of bits in memory, wether you stored an hexa value, an octal one, or a decimal one...

            int i = 0x05;
            //i contains 00000000 00000000 00000000 00000101


            int i = \005;
            //i contains 00000000 00000000 00000000 00000101


            int i = 5;
            //i contains 00000000 00000000 00000000 00000101


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            1 Reply Last reply
            0
            • X xiaohe521

              yes, the diffrent is the string's represent format, i know how to represent a integer to diffrent format string as char *_itoa( int value, char *string, int radix ); but int atoi( const char *string ); the function has only one param, no format param must i write a function to do this? I love Programming

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #7

              Take a look at the sprintf function instead. It will do what you are looking for (and even much more ;) ). Hexa: sprintf(Buffer,"%x",Number); Decimal: sprintf(Buffer,"%d",Number);

              1 Reply Last reply
              0
              • X xiaohe521

                yes, the diffrent is the string's represent format, i know how to represent a integer to diffrent format string as char *_itoa( int value, char *string, int radix ); but int atoi( const char *string ); the function has only one param, no format param must i write a function to do this? I love Programming

                M Offline
                M Offline
                Marc Soleda
                wrote on last edited by
                #8

                An integer is an integer and it doesn't matter how you represent it. If you are trying to print it in different representations you may take a look to print flags[^]. Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.

                1 Reply Last reply
                0
                • X xiaohe521

                  as subject thx I love Programming

                  E Offline
                  E Offline
                  Eytukan
                  wrote on last edited by
                  #9

                  How do u convert a Number to an Integer..?:-D V

                  T 1 Reply Last reply
                  0
                  • X xiaohe521

                    yes, the diffrent is the string's represent format, i know how to represent a integer to diffrent format string as char *_itoa( int value, char *string, int radix ); but int atoi( const char *string ); the function has only one param, no format param must i write a function to do this? I love Programming

                    N Offline
                    N Offline
                    Nishad S
                    wrote on last edited by
                    #10

                    xiaohe521 wrote: int atoi( const char *string ); the function has only one param, no format param must i write a function to do this? I think you are trying to convert a hexadecimal number (which is a string) to an integer. Am I right?

                    1 Reply Last reply
                    0
                    • E Eytukan

                      How do u convert a Number to an Integer..?:-D V

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

                      ah... there's now azt least one interresting post on that thread... :-D:laugh: :rose:


                      TOXCCT >>> GEII power
                      [toxcct][VisualCalc]

                      1 Reply Last reply
                      0
                      • X xiaohe521

                        yes, the diffrent is the string's represent format, i know how to represent a integer to diffrent format string as char *_itoa( int value, char *string, int radix ); but int atoi( const char *string ); the function has only one param, no format param must i write a function to do this? I love Programming

                        M Offline
                        M Offline
                        markkuk
                        wrote on last edited by
                        #12

                        Use the strtol() function to convert numeric strings in various bases into integers.

                        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