By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,141 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,141 IT Pros & Developers. It's quick & easy.

Bitwise Operations on double, float

P: n/a
I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Thanks in advance.

May 17 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
<si******@gmail.comwrote:
>I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Note that your first and second paragraph do not agree, the second on talks
only of doubles. There is an IEEE spec on doubles (and, I think, float)
which is reputedly used quite a bit. If you consider that as "portable" you
could restrict yourself to that and maybe get away with calling it portable.

I can't for the life of me imagine why anyone would want to do this. But I
refuse to ask you, it is none of my business and has no bearing on the
answer to the question.
May 17 '07 #2

P: n/a
On May 17, 5:53 pm, "osmium" <r124c4u...@comcast.netwrote:
<siryu...@gmail.comwrote:
I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.
Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Note that your first and second paragraph do not agree, the second on talks
only of doubles. There is an IEEE spec on doubles (and, I think, float)
which is reputedly used quite a bit. If you consider that as "portable" you
could restrict yourself to that and maybe get away with calling it portable.
I can't for the life of me imagine why anyone would want to do this. ButI
refuse to ask you, it is none of my business and has no bearing on the
answer to the question.
Well, it does, sort of. Because until we know what the
semantics of the operations are supposed to be, it's hard to say
how to best achieve them. What should the result of 1.33 |
3.1419 be? I can't think of anything reasonable.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
May 17 '07 #3

P: n/a
On 17 Maj, 17:34, siryu...@gmail.com wrote:
I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Thanks in advance.
No. Even if you can assume e.g. a IEEE float/double, using bit-magic
will not be portable as the representation might differ (similarly to
how unsigned ints have different endianness on different compters).

/Peter

May 18 '07 #4

P: n/a
On May 17, 4:34 pm, siryu...@gmail.com wrote:
I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Thanks in advance.
I am not sure about the meaning of ANDm OR and XOR for doubles, but <<
can be interpreted as multiplication by 2.0 , similarly >2 can be
interpreted as multiplication by 0.5. This was the opertations are
consistent with the operatrion for integers.

May 18 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.