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. Convert to double value

Convert to double value

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
10 Posts 6 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.
  • A Offline
    A Offline
    ashishbhatt 0
    wrote on last edited by
    #1

    Hi all, i have a problem in the value which stored in memory location.i want to convert it into the double value. Suppose, i have the value int k = 2; when I write it on the memory location like, it is like .. 40 00 00 00 00 00 00 00 But when i retrieve it from memory location then it gives me reverse like... 00 00 00 00 00 00 00 40 So, I want to convert it in to Double value. Little much Strange question, but I am facing this problem. Plz reply me, if u got solution . thanks in advance.

    Ashish Bhatt

    N C C 3 Replies Last reply
    0
    • A ashishbhatt 0

      Hi all, i have a problem in the value which stored in memory location.i want to convert it into the double value. Suppose, i have the value int k = 2; when I write it on the memory location like, it is like .. 40 00 00 00 00 00 00 00 But when i retrieve it from memory location then it gives me reverse like... 00 00 00 00 00 00 00 40 So, I want to convert it in to Double value. Little much Strange question, but I am facing this problem. Plz reply me, if u got solution . thanks in advance.

      Ashish Bhatt

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

      How did you make sure that it is changed? How did you read this "40 00 00 00 00 00 00 00" and "00 00 00 00 00 00 00 40"?

      - NS -

      A 1 Reply Last reply
      0
      • N Nishad S

        How did you make sure that it is changed? How did you read this "40 00 00 00 00 00 00 00" and "00 00 00 00 00 00 00 40"?

        - NS -

        A Offline
        A Offline
        ashishbhatt 0
        wrote on last edited by
        #3

        I have used this code to check the value stored on memory and so I found the output like as explained. double x = 2; unsigned char *str; str = (unsigned char *)malloc(sizeof(unsigned char *)); str = (unsigned char *)&x; CString st, str1; str1 = ""; for(int i = 0; i < 8; i++) { st.Format(CString("%.2X "), *(str++)); str1.Append(st); } AfxMessageBox(str1); here the output like as below.... 00 00 00 00 00 00 00 40 in messagebox.

        Ashish Bhatt

        A N C 3 Replies Last reply
        0
        • A ashishbhatt 0

          I have used this code to check the value stored on memory and so I found the output like as explained. double x = 2; unsigned char *str; str = (unsigned char *)malloc(sizeof(unsigned char *)); str = (unsigned char *)&x; CString st, str1; str1 = ""; for(int i = 0; i < 8; i++) { st.Format(CString("%.2X "), *(str++)); str1.Append(st); } AfxMessageBox(str1); here the output like as below.... 00 00 00 00 00 00 00 40 in messagebox.

          Ashish Bhatt

          A Offline
          A Offline
          Anand Todkar
          wrote on last edited by
          #4

          ashishbhatt wrote:

          00 00 00 00 00 00 00 40 in messagebox.

          The output is correct, what u have to do is to read it in reverse order. I think this is the solution :)

          Thanks, Anand.

          A 1 Reply Last reply
          0
          • A ashishbhatt 0

            I have used this code to check the value stored on memory and so I found the output like as explained. double x = 2; unsigned char *str; str = (unsigned char *)malloc(sizeof(unsigned char *)); str = (unsigned char *)&x; CString st, str1; str1 = ""; for(int i = 0; i < 8; i++) { st.Format(CString("%.2X "), *(str++)); str1.Append(st); } AfxMessageBox(str1); here the output like as below.... 00 00 00 00 00 00 00 40 in messagebox.

            Ashish Bhatt

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

            I checked the code (had to do some corrections). And found that it displays same as that we can see in the Memory window at the time of debug. But you are expecting something different? Can you explain?

            - NS -

            1 Reply Last reply
            0
            • A ashishbhatt 0

              I have used this code to check the value stored on memory and so I found the output like as explained. double x = 2; unsigned char *str; str = (unsigned char *)malloc(sizeof(unsigned char *)); str = (unsigned char *)&x; CString st, str1; str1 = ""; for(int i = 0; i < 8; i++) { st.Format(CString("%.2X "), *(str++)); str1.Append(st); } AfxMessageBox(str1); here the output like as below.... 00 00 00 00 00 00 00 40 in messagebox.

              Ashish Bhatt

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

              :wtf: Woww what are you trying to do ??

              ashishbhatt wrote:

              str = (unsigned char *)malloc(sizeof(unsigned char *));

              This is plain wrong: you will allocate a memory of 4 bytes because unsigned char* is a pointer and a pointer is 4 bytes long. Is that what you want to do ? That's quite a strange way to work...

              ashishbhatt wrote:

              str = (unsigned char *)&x;

              Here you will assign a new address to your str pointer, meaning that you will loose ownership of the previsously allocated memory (now it is 4 bytes of memory that are in memory and you can't access it anymore because you lost its address).

              ashishbhatt wrote:

              st.Format(CString("%.2X "), *(str++));

              Why do you construct a CString inside the Format function ? :confused: And what are you trying to do ?? So, I think your code is just plain wrong. Can you explain what you are trying to do exactly, maybe we'll be albe to help. On a side note, you have to know that the bytes are stored in memory in an inverted way (on windows platforms).


              Cédric Moonen Software developer
              Charting control [v1.2]

              1 Reply Last reply
              0
              • A Anand Todkar

                ashishbhatt wrote:

                00 00 00 00 00 00 00 40 in messagebox.

                The output is correct, what u have to do is to read it in reverse order. I think this is the solution :)

                Thanks, Anand.

                A Offline
                A Offline
                ashishbhatt 0
                wrote on last edited by
                #7

                ya thats right but i want the reverse process. I have that reverse data('40 00 00 00 00 00 00 00') now i want its double value('2') of this data without storing it into memory Any idea? Thanks in advance

                Ashish Bhatt

                A 1 Reply Last reply
                0
                • A ashishbhatt 0

                  Hi all, i have a problem in the value which stored in memory location.i want to convert it into the double value. Suppose, i have the value int k = 2; when I write it on the memory location like, it is like .. 40 00 00 00 00 00 00 00 But when i retrieve it from memory location then it gives me reverse like... 00 00 00 00 00 00 00 40 So, I want to convert it in to Double value. Little much Strange question, but I am facing this problem. Plz reply me, if u got solution . thanks in advance.

                  Ashish Bhatt

                  C Offline
                  C Offline
                  codeII
                  wrote on last edited by
                  #8

                  You cannot change these types in memory, because int and double have different sizes in memory. Else you could have changed your type in memory like this:

                  int nTst = 2;
                  double dTmp = (double) nTst;
                  double* pTst = (double*)&nTst;
                  *pTst = dTmp;

                  Is this what you meant?

                  1 Reply Last reply
                  0
                  • A ashishbhatt 0

                    ya thats right but i want the reverse process. I have that reverse data('40 00 00 00 00 00 00 00') now i want its double value('2') of this data without storing it into memory Any idea? Thanks in advance

                    Ashish Bhatt

                    A Offline
                    A Offline
                    Anand Todkar
                    wrote on last edited by
                    #9

                    ashishbhatt wrote:

                    I have that reverse data('40 00 00 00 00 00 00 00') now i want its double value('2') of this data without storing it into memory

                    For this to happen, you need to convert the data from memory to equivalent binary and then to convert that binary to decimal. I find this as a solution.

                    Thanks, Anand.

                    1 Reply Last reply
                    0
                    • A ashishbhatt 0

                      Hi all, i have a problem in the value which stored in memory location.i want to convert it into the double value. Suppose, i have the value int k = 2; when I write it on the memory location like, it is like .. 40 00 00 00 00 00 00 00 But when i retrieve it from memory location then it gives me reverse like... 00 00 00 00 00 00 00 40 So, I want to convert it in to Double value. Little much Strange question, but I am facing this problem. Plz reply me, if u got solution . thanks in advance.

                      Ashish Bhatt

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

                      hai ashish, can you explain exactly what you want, as Cedric Moonen said, may be we will be able to help.

                      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