473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Oct 23 '07 #1
4 2347
gpraghuram
1,275 Expert 1GB
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
How are u retrieving it from memory...usually this wont happen .

Raghuram
Oct 23 '07 #2
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.
Oct 23 '07 #3
gpraghuram
1,275 Expert 1GB
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.

Hi,
You cant read double values using this approach because the double and float are stored using the IEEE format and you can get an idea about it if u search in the net.
Also there are some minor issues in the code
You need not allocate memory for str variable and as you use %x as format specifier i dont think you can get the actual value as it gets converted to hex(i am not sure abt this)

Raghuram
Oct 23 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Let's go back to int k = 2;

In binary that's:

0000 0000 0000 0000 0000 0000 0000 0010
<-byte 3-> <-byte 2-> <-byte 1-> <-byte 0->

If you are big-endian (like Unix/Linux) the bytes are written:

Address:
0 byte 3
1 byte 2
2 byte 1
3 byte 0

If you are little-endian (like Windows) the bytes are written:
Address:
0 byte 0
1 byte 1
2 byte 2
3 byte 3

Hence the bit pattern in memory will be different.
Oct 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
9
by: photomonkey | last post by:
I am having a problem with a relatively simple sql query, and was hoping that somebody could help me on this forum. Basicaly the situation is that I have two tables, a Vendors table (Vendors)...
2
by: Pascal | last post by:
Why does this not work, and how should i do this convert in stead: string x = double.MinValue.ToString(); double y = Convert.ToDouble(x); i get this exception: An unhandled exception of type...
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
3
by: Eric BOUXIROT | last post by:
hi, i must convert all of these eVC++ prototypes to use with VB.NET.... DLLEXPORT long F_BDO_MessageBoxOK(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_MessageBoxOUINON(char *IN_title,...
3
by: PeterK | last post by:
I am trying to set Public overridable CreditlimitS() as System.Data.SqlTypes.SqlMoney to Creditlimit as Double like CreditLimitS=creditlimit and get this error "Value of type double cannot be...
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
3
by: rishabhshrivastava | last post by:
Hello All, How can I convert a value to Double in JavaScript??? In vbscript i believe its done as cDbl(Value) I tried lots of way but getting a value of "NaN". Any suggestions/ideas will...
8
by: shiniskumar | last post by:
Ive got a double variable dTotal =5.037717235E7 i formatted it using deciFormat.format(dTotal) and got the String value of dTotal=50377172.35 now i have to pass this value as an argument to a...
3
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.