Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a byte a byte array from a double value

Status
Not open for further replies.

stonee74

Technical User
Nov 12, 2001
49
0
0
CH
Hi Guys,
I am currently developing a Client/Server program in Java. The server I try to understand sends somewhat unsigned double values whereas in JAVA only signed doubles do exist.
However, can anybody give my an idea how to generate in C(++) a byte array from any double value to the console in order to find a suitable algorithm for my app.

any help is greatly appreciated!

regards,
stonee
 
Try this:

double d;
byte* p = (byte*)&d;

for (i=0; i<sizeof(double); i++)
printf(&quot;0x02x &quot;, *(b+i) );
printf(&quot;\n&quot;);
 
I found a way by myself, thanks anyway..
stone

main (int argc, char* argv[])
{
;
double d;

unsigned char* b1 = (unsigned char*)&d;
char* b2 = (char*)&d;


while(1)
{
printf(&quot;double?: \n&quot;);
scanf(&quot;%g&quot;,&d);

for (int i=0; i<sizeof(d); i++)
{
printf(&quot;byte: %i, signed int %i,unsigned int %i&quot;, (i),*(b1+i),*(b2+i) );
printf(&quot;\n&quot;);
}
}

}
 
ehmmm once again:
is this correct what i did?
Does anybody know the correct specification of a floating point number in IEE754?
Is the composition a such a double in C++ and Java the same?
obviously not...

thanks for any ideas,
stonee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top