5 Replies Latest reply: Jan 6, 2008 7:10 PM by 807601 RSS

    incrementing hex values

    807601
      how can i increment HEX value like

      0x00 0x11
      0x01 0x12 ....
      0x02 0x13 ....
      0x03 0x14 ....
      .. ..
      ..
      .. .. 0x98
      0x10 0x20 ..................... 0x99


      is there any way to make a loop ....i want to increment up to 0x99.
        • 1. Re: incrementing hex values
          807601
          int a = 0x10;
          a++;
          • 2. Re: incrementing hex values
            807601
            Values are just values, they're not hexadecimal or octal or decimal or binary. (Well, they're all stored as a sequence of bits, so you could say that they're all binary in a sense, but the representation in characters is irrelevant to the values.)

            So just increment a variable normally, and if you so choose you can display it in hex.
            • 3. Re: incrementing hex values
              807601
              Actually i have a hex value 0x1000 which i have to divide to 0x10 and 0x00 and have to increment it. When i am incrementing in a loop like this

              int i= 0x00;
              i++;

              i am getting sequence of integer values from 1.......loop ending which is not equivalent to its hex value.

              for example if the loop is 1 to 15 then i am getting output as

              1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

              but for 0x10 decimal value is 16, 0x11 value is 17 so on

              hex value....... original int value ................ getting int value in my o/p

              0x00......................1................................. 1
              0x01......................2................................. 2

              0x10......................16................................. 10
              0x11......................17................................. 11

              the problem is when 0x00 is incrementing its value is becoming 1 which is stored as "i" value now and this value is incrementing instead of original hex value(0x01,0x02..........0x15)

              how can i get the original int value on incrementing the hex value.
              • 4. Re: incrementing hex values
                807601
                Probably it's me, but I am confused by your most recent post, not the least of which I always thought that 0x00 == 0 not 1, and 0x01 == 1. My recommendation is to show your code. When posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, either use the "code" button at the top of the forum Message editor or place the tag [code] at the top of your block of code and the tag [/code] at the bottom, like so:

                [code]
                  // your code block goes here.
                [/code]
                • 5. Re: incrementing hex values
                  807601
                  Any number plus one is a new number one bigger than the original one.

                  IT MAKES NO DIFFERENCE WHETHER THE NUMBER IS EXPRESSED IN DECIMAL, HEX, OCTAL, OR BINARY.

                  As already noted you seem to be confused about hex anyway. 0 decimal is 0 hex is 0 octal is 0 anything.

                  My suggestion: read up about what hexadecimal is.