Convert to double value
-
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
-
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
-
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 -
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
-
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
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.
-
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
-
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
: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] -
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.
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
-
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
You cannot change these types in memory, because
int
anddouble
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?
-
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
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.
-
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