471,627 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Conversion Question

JRB
Hi, here is what I'm doing. I've got 4 bytes that represent a number in IEEE
format. I'm placing them in a double variable like so:
double myDouble = byte[0] << 24 | byte[1] << 16 | byte[2] << 8 | byte[3];
Since the double data type is an IEEE format, shouldn't the variable now be
a floating point number? When I print it out I get a large integer number.
What is happening here? Thanks.
Feb 13 '06 #1
2 1423
JRB wrote:
Hi, here is what I'm doing. I've got 4 bytes that represent a number in IEEE
format. I'm placing them in a double variable like so:
double myDouble = byte[0] << 24 | byte[1] << 16 | byte[2] << 8 | byte[3];
Since the double data type is an IEEE format, shouldn't the variable now be
a floating point number? When I print it out I get a large integer number.
What is happening here?


What's happening is that you're shifting a lot of bytes, and getting an
integer. There's nothing in the RHS to suggest that there should be any
floating point arithmetic involved.

Have a look at BitConverter.ToDouble to solve your problem - but try to
understand why your solution didn't work, first.

Jon

Feb 13 '06 #2
JRB,
double myDouble = byte[0] << 24 | byte[1] << 16 | byte[2] << 8 | byte[3];
Since the double data type is an IEEE format, shouldn't the variable now
be
a floating point number?
No way! You are getting an integer value corresponding to the INTERNAL
REPRESENTATION of the floating point number, which has nothing to do with
the floating point number itself.

As John said, use the BitConverter class.

BTW, if you have four bytes, it is a float, not a double.

Regards - Octavio
When I print it out I get a large integer number. What is happening here? Thanks.

Feb 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Russell Reagan | last post: by
5 posts views Thread by Vijai Kalyan | last post: by
7 posts views Thread by Michael Lehn | last post: by
26 posts views Thread by David W. Fenton | last post: by
31 posts views Thread by Bjrn Augestad | last post: by
4 posts views Thread by Nikhil Patel | last post: by
2 posts views Thread by Alex Sedow | last post: by
1 post views Thread by hunter hou | last post: by
21 posts views Thread by REH | last post: by
1 post views Thread by XIAOLAOHU | last post: by

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.